[英]C# How can i split a string on first number?
I have the following string "ABCD EFG 201 E"
i want to split it on the first number that it founds a digit and return both strings Ex.我有以下字符串
"ABCD EFG 201 E"
我想在它找到数字的第一个数字上拆分它并返回两个字符串 Ex。 "ABCD EFG"
and "201 E"
"ABCD EFG"
和"201 E"
i tried Regex.Split and other stuff but i don't get it.我尝试了 Regex.Split 和其他东西,但我不明白。 can someone help me please?
有谁可以帮助我吗? Thanks, Best Regards.
谢谢,最好的问候。
not using regex cos I dont really like them - story goes "you have a problem, you decide to use regex on it, you now have 2 problems"不使用正则表达式,因为我真的不喜欢它们 - 故事是“你有问题,你决定在上面使用正则表达式,你现在有 2 个问题”
char[] digits = {'0','1','2','3','4','5','6','7','8','9'};
string s = "ABCD EFG 201 E";
var idx = s.IndexOfAny(digits);
if (idx !=-1){
var first = s.Substring(0,idx);
var second = s.Substring(idx);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.