trim the string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a string line = " DOL : 12/04/09 "

I want to remove the white spaces and to get the string like
line = "DOL : 12/04/09" ;

i have th e following coding but it is not going to if statement.

line.Trim();
if (line.StartsWith("DOL"))
{
start++;
}
 
seema,

Calling methods that perform adjustments on the string actually return a
new instance of a string with the adjustments applied. In this case, you
have to do this:

line = line.Trim();

if (line.StartsWith("DOL"))
....
 
string line = " DOL : 12/04/09 ";
string x = line.Trim();

if(x.StartsWith("DOL"))
{
//do something
}
 
without a new string variable or reassigning the value of line

if(line.Trim().StartsWith("DOL"))
{
//do something
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top