Wednesday, March 28, 2012

substrings

i don't know if it is because it's friday, or the last day of my internship, or if i'm just retarted but..I've got string data such as CLIENT/Bob and want to drop the client part. I know i've gotta use substring, but the client part changes so i was wondering if i can use substring in a manner which will allow to me to get everything after the backslash.

first, use the indexOf property to find the position of the slash

Dim myVar as string
Dim pos as Integer
myVar="Client/Bob"
pos=myVar.IndexOf("/")
myVar=myVar.SubString(pos)

this may need a little tweaking - it's all ottomh


string user = "CLIENT/bob";

string usernoclient = user.SubString(user.LastIndexOf("/")+1);


string text = "CLIENT/Bob";
if (text.Length > 0 && text.IndexOf("/") >=0)
{
string client = text.Substring(text.IndexOf("/") + 1, text.Length - (text.IndexOf("/") + 1));
}

Thanks

0 comments:

Post a Comment