Thursday, April 25, 2013

How to remove last character from string in C#

Suppose you have the following sentence:
"Riyadh - Jeddah - Dammam -"
which comes from list of cities and separated by (-) after each city.
you need to remove last separator.

just use the following code:

// remove last separator
 if (lblInputRegions.Text.EndsWith("-"))
         lblInputRegions.Text = lblInputRegions.Text.Remove((lblInputRegions.Text.Length - 1), 1);

No comments:

Post a Comment