How to trim the last character of a string

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have a string variable lik:
sList="1.Tiger, 2.Wolf, 3.Rabbit,"
I want to trim off the last character ","

Have there pre-define function to do that?
 
ad said:
I have a string variable lik:
sList="1.Tiger, 2.Wolf, 3.Rabbit,"
I want to trim off the last character ","

Have there pre-define function to do that?

If you always want to remove the last character, just use:

sList = sList.Substring (0, sList.Length-1);

Or if it's always going to be a comma, and won't be preceded by a
comma, you could just use:

sList = sList.TrimEnd(',');
 
Back
Top