tags:

views:

69

answers:

2

I have a string that could look like this: smithj_Website1 or it could look like this rodgersk_Website5 etc, etc. I want to be able to store in a string what is after the "_". So IE (Website1, Website5,..)

Thanks

+7  A: 

Should be a simple as using substring

string mystr = "test_Website1"
string theend = mystr.SubString(mystr.IndexOf("_") + 1)
// theend = "Website1"

mystr.IndexOf("_") will get the position of the _ and adding one to it will get the index of the first character after it. Then don't pass in a second parameter and it will automatically take the substring starting at the character after the _ and stopping and the end of the string.

Bob Fincheimer
Awesome Bob.. And what if I wanted to get what was in front the "_" in a different string?
Josh
That's a good problem for you to figure out.
palswim
wow thanks palswim. how nice of you
Josh
I got the last part figured out using remove(). Thanks again Bob and others
Josh
+3  A: 
int startingIndex = inputstring.IndexOf("_") + 1;
string webSite = inputstring.Substring(startingIndex);

or, in one line:

string webSite = inputstring.Substring(inputstring.IndexOf("_") + 1);
AllenG