开发者

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

开发者 https://www.devze.com 2023-02-14 00:02 出处:网络
I am seeking to parse out the Employee\'s Id from strings that contain my company\'s domain.For example:

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

精彩评论

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

关注公众号