如何拆分“T1001”进T和1001 ..?

问题描述:

我有一个值为TR T1001的字符串

i使用拆分方法将值TR和T1001分开以下代码

hi im having a string with value "TR T1001"
i used split method to separate the values TR and T1001 bu the following code

string item1="TR T1001"
string[] arrvalue=item1.Split(' ');
string sBeforeSpace=arrvalue[0];
string sAfterSpace=arrvalue[1];



所以通过使用这个代码将TR加入sBeforeSpace并将T1001加入到

sAfterSpace中。



但仍然我必须将T1001拆分为T和1001

应该用Split(???)方法写入什么值?


so by using this code im geeting "TR" into sBeforeSpace and "T1001" into
sAfterSpace.

but still i have to split "T1001" into "T" and "1001"
what value should be written in Split(???) method?

第二个选项不使用 Split ,但 SubString [ ^ ]。
You do not use Split for the second option, but SubString[^].


您可以在C#中使用子字符串



学习 [ ^ ]



并使用

You can use substring in C#

Learn [^]

and use
string item1 = "T1001";
        string a = item1.Substring(0, 1);
        string b = item1.Substring(1, 4);


您可以使用正则表达式 [ ^ ]:

You can use Regex[^]:
string s = "TR T1001";
string pat = @"\d+";

string res = Regex.Match(s, pat).Value;
Console.WriteLine(res);



结果: 1001



要将其转换为整数,请使用 Int32 .TryParse [ ^ ]方法。