views:

287

answers:

3

Say I have a string whose text is something like, "mohdibrahim.tasal". I want to extract "mohdibrahim" from this string.

I've tried this code:

string updateUser1 = user1.Trim();

Is this the correct approach, or is there another technique I should be using?

A: 

try

string updateUser1 = user1.Substr(user1.IndexOf(".")+1);

I haven't tested it though.

Marius
This will return everything *after* the first period, not before.
DSO
wow, I could have sworn it said "after", not "before".
Marius
+3  A: 

OK, lets assume i think i know what you want.

Try

string user = user1.Split('.')[0];

This will split the string on the '.' and return the last part.

astander
I think the OP wants `string user = user1.Split('.')[0] to get "mohibrahim"
ChrisF
Thanx, fixed it.
astander
+4  A: 

This will return everything before the period(".")

string updateUser1 = user1.Substring(0,user1.IndexOf("."));
geoff