algorithm - How to compare number zero programmatically when the keyboard language is changed from english to other language in C# -


i want compare 0 coming textbox string removing front in c#.

 private string removeleadingzeros(string str)//textbox.text         {             int index = -1;             (int = 0; < str.trim().length; i++)             {                 if (str[i] == '0')//this comparison fails if change keyboard language english other language ex. chinese                     continue;                 else                 {                     index = i;                     break;                 }             }              return (index != -1) ? str.substring(index) : "0";         } 

so, example if string "0001" should return 1. method fails if change keyboard language other english (example:chinese).

how can compare 0 irrespective of language changed keyboard english other language?

i checked font containing cjk characters (microsoft jhenghei on windows 10), , inferred chinese keyboard layout return full-width numbers (starting @ u+ff10). other keyboard layouts may provide different numbers, appear best choice use char.getnumericvalue() method (see what's deal char.getnumericvalue?).

edit: substring() single parameter returns same string if index 0. added trimming in original post, changed method name reflect it, , made extension method.

with that, method follows:

private static string trimandremoveleadingzeros(this string str) {     int idx = 0;     if (string.isnullorempty(str)) return str;     str = str.trim();     (int = 0; < str.length; i++)     {         int num = (int)char.getnumericvalue(str[i]);         if (num == 0) idx++;         else break;     }     return str.substring(idx); } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -