Ekona Pikin

Ekona Pikin

  • NA
  • 38
  • 13.2k

Trim a string after a spoecial character

Feb 23 2015 2:54 PM
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);

Answers (3)