azeem
azeem

Reputation: 351

remove dot at end of text

i have to remove the dot at the end of text howt to i do

usign c#, dot.net

example = abc.

i want this = abc

Upvotes: 9

Views: 7938

Answers (2)

Guffa
Guffa

Reputation: 700680

You can remove any dots at the end of a string using the TrimEnd method:

str = str.TrimEnd('.');

You can use the Substring method to remove only the last character:

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

If the last character should only be removed if it's a period, you can check for that first:

if (str[str.Length - 1] == '.') {
  str = str.Substring(0, str.Length - 1);
}

Upvotes: 11

Matt Mitchell
Matt Mitchell

Reputation: 41853

Try this:

string a = "abc.";
string b = a.TrimEnd('.'); 

Upvotes: 30

Related Questions