删除hexstring中的空格 [英] Remove whitespace in hexstring
本文介绍了删除hexstring中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个六弦,然后转换为字符串,但输出是+ 9 1 1 2 3 4 5 6 7 8 9
所以我想删除所有空格并获得仅限+91123456789的数字
我尝试过:
I have one hexastring then convert to string but output is + 9 1 1 2 3 4 5 6 7 8 9
so i want to remove all white space and get only number like +91123456789
What I have tried:
string MobileNumber = " + 9 1 1 2 3 4 5 6 7 8 9 ";
MobileNumber = Regex.Replace(MobileNumber, @"\s+", "");
推荐答案
这是来自:从.NET中的字符串中删除所有空格的最快方法 [ ^ ]
This is from: Fastest method to remove all whitespace from Strings in .NET[^]
static Regex whitespace = new Regex(@"\s+", RegexOptions.Compiled);
public static string TrimAllWithRegex(string str) {
return whitespace.Replace(str, "");
}
正则表达式删除字符串有点过头了,不是吗?
为什么不只是
regex for String removal is a little bit over the top, isn't it?
why not just
number = number.Replace(" ","");
我想知道为什么你还有空格,解析HEX不应该......
I wonder why you have spaces anyway, parsed HEX shouldn't have ...
这篇关于删除hexstring中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文