Link to home
Start Free TrialLog in
Avatar of johnkainn
johnkainn

asked on

remove part of string

I have a string. I want to find the last instance of "(" and remove it and everything that is behind it.
For example:"skj(ælsu(39)".  I would like to return: "skj(ælsu"
How do I do that
Avatar of adathelad
adathelad
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

This should do the trick:
string val = "skj(ælsu(39)";
int lastPosition = val.LastIndexOf('(');
if (lastPosition>0)
    val = val.Substring(0, lastPosition);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of adathelad
adathelad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
string x = "skj(ælsu(39)";
if(x.Contains('(')
x=x.Substring(0,x.LastIndexOf('(');
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial