Reputation: 60751
i have a string like this:
some_string="A simple demo of SMS text messaging." + Convert.ToChar(26));
what is the SIMPLEST way of me getting rid of the char 26?
please keep in mind that sometimes some_string has char 26 and sometimes it does not, and it can be in different positions too, so i need to know what is the most versatile and easiest way to get rid of char 26?
Upvotes: 3
Views: 602
Reputation: 61981
If it's only at the end:
some_string.TrimEnd((char)26)
If it can be anywhere then forget this and use Jon Skeet's answer.
Upvotes: 4
Reputation: 1500825
If it can be in different positions (not just the end):
someString = someString.Replace("\u001A", "");
Note that you have to use the return value of Replace
- strings are immutable, so any methods which look like they're changing the contents actually return a new string with the appropriate changes.
Upvotes: 6