简体   繁体   中英

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  --> all 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.

使用stringVar.Split("\\\\")[1]并查看http://msdn.microsoft.com/zh-cn/library/system.string.split.aspx了解详细信息。

这个怎么样:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM