在C#中拆分InnerText [英] Splitting InnerText in C#
问题描述
我需要协助在C#中拆分InnerText。下面是如何在ComboBox中显示InnerText。我需要的只是第一个销售人员和员工编号。每个销售人员信息都格式化姓氏,Fistname员工编号Thyere
可以是后缀和中间首字母。在这种情况下 SMITH JR,JOHN 1245481 。请注意,销售人员列表可能会根据分支进行更改。我只需要每次都能在列表中拆分第一个。
来自ComboBox的InnerText =
售货员:   未分配/无SMITH JR,JOHN 1245481EARL,JAMES 654782REID,ARTHUR 5498752BRADLEY,J TYLER 1378289NEWTON,CAM 1291403RICE,G JERRY 318615DE FLIPPE,JESSE 1183512DESTREZA,A ALFONSO 451810
我是尝试了以下内容:
//这是组合从中拉出内部文本的框 String
SalespersonComboBox = UIMap.UIInternetWindow2.UIDocument.UISalesPersonsComboBox1.InnerText;
//此拆分文本为Unassigned / None SMITH JR
字符串 FirstSalesperson = SalespersonComboBox.Split( ',' )[0] .Trim();
//将文本拆分为BACON
字符串 SalespersonName = FirstSalesperson.Split( '' )[3] .Trim();
最终需要的是第一个销售人员的全名和员工编号,在这种情况下
SMITH JR,JOHN 1245481
不最好的代码,但这对我有用:
var example =" Unassigned / None SMITH JR,JOHN 1245481EARL,JAMES 654782REID,ARTHUR 5498752BRADLEY,J TYLER 1378289NEWTON,CAM 1291403RICE,G JERRY 318615DE FLIPPE,JESSE 1183512DESTREZA,A ALFONSO 451810" ;;
var splitExample = example.Split('');
var name = splitExample [3] +"" + splitExample [4] +"" + splitExample [5];
var number = Regex.Replace(splitExample [6]," [^ 0 -9。]","");
Console.WriteLine(name +"" + number);
不要忘记添加以下使用声明:
使用System.Text.RegularExpressions;
编辑:这个问题应该在C#论坛。
I need assistance with splitting InnerText in C#. Below is how the InnerText is displayed in the ComboBox. All I need is the first salesperson and employee number. Each salesperson information is formatted Lastname, Fistname Employee Number Thyere may be a suffix and middle initial. in this case SMITH JR, JOHN 1245481. Note the list of sales people may change depending on the branch. I just need to be able to split the first one on the list each time.
InnerText from ComboBox=
Salesperson: Unassigned / None SMITH JR, JOHN 1245481EARL, JAMES 654782REID, ARTHUR 5498752BRADLEY, J TYLER 1378289NEWTON, CAM 1291403RICE, G JERRY 318615DE FLIPPE, JESSE 1183512DESTREZA, A ALFONSO 451810
I’ve tried the following already:
//This is the combo box where I pull the inner text fromString SalespersonComboBox = UIMap.UIInternetWindow2.UIDocument.UISalesPersonsComboBox1.InnerText;
// This split text to Unassigned / None SMITH JR
String FirstSalesperson = SalespersonComboBox.Split(',')[0].Trim();
//This splits text to BACON
String SalespersonName = FirstSalesperson.Split(' ')[3].Trim();
What is ultimately need is the first salesperson full name and employee number, in this case SMITH JR, JOHN 1245481
Not the nicest code, but this worked for me:
var example = "Unassigned / None SMITH JR, JOHN 1245481EARL, JAMES 654782REID, ARTHUR 5498752BRADLEY, J TYLER 1378289NEWTON, CAM 1291403RICE, G JERRY 318615DE FLIPPE, JESSE 1183512DESTREZA, A ALFONSO 451810"; var splitExample = example.Split(' '); var name = splitExample[3] + " " + splitExample[4] + " " + splitExample[5]; var number = Regex.Replace(splitExample[6], "[^0-9.]", ""); Console.WriteLine(name + " " + number);
Don't forget to add the following using statement:
using System.Text.RegularExpressions;Edit: this question should be in the C# forum.
这篇关于在C#中拆分InnerText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!