Reputation: 3855
in vb.net i have a string that looks like this
"text text text
"
so in the end of it there are spaces and a new empty line
How can make this look like
"text text text"
Upvotes: 2
Views: 6441
Reputation: 58
Use the string.TrimEnd(params char[] trimChars)
method:
yourString.TrimEnd();
Upvotes: 1
Reputation: 14213
I'm not sure that Trim() will cut the new lines too...if not you can use it with param - Trim('\n') or Trim('\t') for tabs or even specify a list of characters which you'd like to cut off.
Upvotes: 2
Reputation: 6079
Dim value As String = "text text text
"
Dim trimmed As String = value.Trim()
Trim removes leading and trailing whitespace. String data often has leading or trailing whitespace characters such as newlines, spaces or tabs. These characters are usually not needed. With Trim we strip these characters in a declarative way.
Reference: http://www.dotnetperls.com/trim-vbnet
Upvotes: 2
Reputation: 65059
string.TrimEnd
:
var s = @"text text text
";
Console.Write(s.TrimEnd() + "<-- End"); // Output: text text text<-- End
TrimEnd
trims from the end of the string, Trim
removes from both the beginning and end of the string.
Upvotes: 6