I have a string like this "ALTA Homeowner's Policy of Title Insurance". I want to remove colon from above string(which one beside home owner)? how to do this by using C#
Asked
Active
Viewed 1,509 times
-4
-
Are you referring to the `'` character? That is known as an _apostrophe_ or a _single quote_. A _colon_ looks like this: `:` – Kristopher Johnson Jul 07 '15 at 17:59
-
There's no colon in your string, but if you want to remove a character from a string, I think this is something you may found on google. – The_Black_Smurf Jul 07 '15 at 17:59
-
possible duplicate of [Remove characters from C# string](http://stackoverflow.com/questions/7411438/remove-characters-from-c-sharp-string) – Kristopher Johnson Jul 07 '15 at 18:02
1 Answers
0
One way is finding the index of colon and then using remove method available for String object.
int index;
string s = "ALTA Homeowner's Policy of Title Insurance";
string output;
index = s.IndexOf('\'');
if (index != -1)
{
output = s.Remove(index, 1);
Console.Out.WriteLine(output);
}
Escape character '\' is used to catch colon.
IndexOf method return the index of first occurance of a matching character. Other methods like IndexOfAny,LastIndexOf are also available.

Rohit
- 895
- 1
- 9
- 19