FPGA
FPGA

Reputation: 3855

remove spaces and empty line in the end of a string vb.net

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

Answers (5)

TheProgrammer
TheProgrammer

Reputation: 58

Use the string.TrimEnd(params char[] trimChars) method:

yourString.TrimEnd();

Upvotes: 1

daneejela
daneejela

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

andy
andy

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

Simon Whitehead
Simon Whitehead

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

SLaks
SLaks

Reputation: 887285

You're looking for the Trim() method.

Upvotes: 2

Related Questions