What is the best way to use regex and remove everything after (":") using c#
I have a richtextbox and its populated with data that I load .
The data contain bunch of itemcodes some have (colon) and alphanumeric characters I dont need like for instance RE45O7:TAKEMOUT==> I just want to be able to have RE4507
This is what I have but is not working...
string str = rchTxtContent.Text;
string ext = str.Substring(str.LastIndexOf(":") + 1);
Trim a string after a spoecial character
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


VulpesRank #55 · 29.2K reputationPosted Feb 23, 2015, 11:02 AM EST
string str = rchTxtContent.Text;
Ekona Pikin38 reputationPosted Feb 23, 2015, 11:37 AM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 23, 2015, 7:26 PM EST
No need to use Regex.
also try...
string str = "wewew:erere:erere:rtr";
int index = str.LastIndexOf(':');
Console.WriteLine(str.Remove(index));