-3

Hi I have a mix type of string. i want to remove special symbol from word which are using end of the words only. for ex.

 "Kapil-Kumar?hasija--

i need to remove special symbols which are coming after my sentence. So for this i need to find position of my last alphabet.

Prahalad Gaggar
  • 11,389
  • 16
  • 53
  • 71

1 Answers1

1

You could use this:

string s = "Kapil-Kumar?hasija--";

while (s.Length > 0 && !Char.IsLetter(s[s.Length-1]))
  s = s.Substring(0, s.Length-1);

Console.WriteLine(s); // prints "Kapil-Kumar?hasija"

If digits are also permitted at the end, use Char.IsLetterOrDigit instead of Char.IsLetter.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111