Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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+", "");
Posted
Updated 14-May-17 20:27pm

This is from: Fastest method to remove all whitespace from Strings in .NET[^]
C#
static Regex whitespace = new Regex(@"\s+", RegexOptions.Compiled);

public static string TrimAllWithRegex(string str) {
    return whitespace.Replace(str, "");
}
 
Share this answer
 
regex for String removal is a little bit over the top, isn't it?

why not just
C#
number = number.Replace(" ","");


I wonder why you have spaces anyway, parsed HEX shouldn't have ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900