[英]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. 我正在尝试从包含我公司域的字符串中解析出员工ID。 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.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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.