简体   繁体   English

如何解析员工的域和ID与之间的“ \\”?

[英]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.

相关问题 如何通过员工 ID 将员工添加到项目中 - How to add employee to project by employee id 如何通过员工 ID 搜索 DropdownList? - How to search DropdownList by Employee ID? 如何根据员工收入中员工薪水排名第二的基于身份证的LINQ选择不同的员工? - How to select distinct employees with LINQ based on ID from an employee collection where employee 's salary is 2nd highest? 如何使用文本框和按钮通过 id 查找员工 - How to find employee by id with textbox and button C#从列表中过滤员工ID以修改查询 - C# Filtering employee ID's from a list to modify a query 如何通过 id,name,exp 以最佳方式让员工使用 - how to get employee using optimal way by id,name ,exp 如何添加员工 ID 并为员工创建集合和列表? - how do I add employee ID and create collection and list for employees? 如何将角色列表的role_Id元素添加到员工列表中? - How to add role_Id element of role List to employee List? 如何在Employee实体和ICollection之间使用Fluent API设置关系 <Employee> ? - How do I set up the relation using Fluent API between an Employee entity and an ICollection<Employee>? 我如何纠正&#39;qual.employee_id =人才招聘.employee_id中的错误“无法将类型&#39;int&#39;隐式转换为&#39;string&#39;”; &#39;? - How do I correct the error “cannot implicitly convert type 'int' to 'string'” in ' qual.employee_id = recruitment.employee_id; '?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM