开发者

How to parse employee's domain and Id with "\" in between?

I am seeking to parse out the Employee's Id from strings that contain my company's domain. For example:

domain\empId  --> all I want is "empId"
test\x123  --> al开发者_开发技巧l I want is "x123"
qa\e24  --> all I want is "e24"

Basically, given a string, I would like everything after the "\".

Any advice will be greatly appreciated.


var result = inputString.Split(@"\")[1];


Use String.Split:

string s = @"domain\empId";
string value = s.Split('\\')[1];
Console.WriteLine(value);

Output:

empId


Do you mean

userName.Substring(userName.IndexOf('\\')+1);

This is the fastest.


Use stringVar.Split("\\")[1] and check out http://msdn.microsoft.com/en-us/library/system.string.split.aspx for details.


How about this:

s.Substring(s.LastIndexOf('\\') + 1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜