Trim string from the end of a string in .NET - why is this missing?

前端 未结 13 1334
夕颜
夕颜 2020-12-13 12:08

I need this all the time and am constantly frustrated that the Trim(), TrimStart() and TrimEnd() functions don\'t take strings as inputs. You call EndsWith() on a string, an

13条回答
  •  [愿得一人]
    2020-12-13 12:34

    The following example demonstrates how to extract individual words from a block of text by treating white space and punctuation marks as delimiters. The character array passed to the separator parameter of the String.Split(Char[]) method consists of a space character and a tab character, together with some common punctuation symbols.

    string words ="sfdgdfg-121";
    string [] split = words.Split(new Char [] {' ', ',', '.', ':', '-' });
    foreach (string s in split)
    {
        if (s.Trim() != "")              
            Console.WriteLine(s);
    }
    

    Try this code.

提交回复
热议问题