How to extract text before a period from a string in C#?
Say I have a string whose text is something like, "mohdibrahim.tas开发者_StackOverflowal"
. 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?
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.
This will return everything before the period(".")
string updateUser1 = user1.Substring(0,user1.IndexOf("."));
try
string updateUser1 = user1.Substr(user1.IndexOf(".")+1);
I haven't tested it though.
精彩评论