String and non english characters
-
I have a string. The value of that string contains some english and non english characters. I have two requirements: 1) Determine whether the string contains non english characters. 2) Remove all the non english characters from the string and get the resultant string which contains only english characters. How can i do so ?
Imtiaz
-
I have a string. The value of that string contains some english and non english characters. I have two requirements: 1) Determine whether the string contains non english characters. 2) Remove all the non english characters from the string and get the resultant string which contains only english characters. How can i do so ?
Imtiaz
Convert each character into a byte (you can use the convert class), and then check the byte's against the ASCII table. capital A to Z = 65->90 numeric lower case A to Z = 97->122 numeric. You would have to check for other characters you wanted to keep though. (i.e comma's fullstops etc etc).
string word = "fdffd"; foreach (char c in word) { byte b = Convert.ToByte(c); if ((int)b > 65 && (int)b < 90) { // Upper case ASCII letter } else if ((int)b < 97 || (int)b > 122) { // lower case ASCII letter } else { word.Replace(c.ToString(), string.Empty); } }
Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen Click here to view my blog
-
Convert each character into a byte (you can use the convert class), and then check the byte's against the ASCII table. capital A to Z = 65->90 numeric lower case A to Z = 97->122 numeric. You would have to check for other characters you wanted to keep though. (i.e comma's fullstops etc etc).
string word = "fdffd"; foreach (char c in word) { byte b = Convert.ToByte(c); if ((int)b > 65 && (int)b < 90) { // Upper case ASCII letter } else if ((int)b < 97 || (int)b > 122) { // lower case ASCII letter } else { word.Replace(c.ToString(), string.Empty); } }
Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen Click here to view my blog
MarkBrock wrote:
Convert each character into a byte
That seems unnecessary, as does the casting to int. If you want to do it that way, just use
if ( ( c >= 'A' ...
-
I have a string. The value of that string contains some english and non english characters. I have two requirements: 1) Determine whether the string contains non english characters. 2) Remove all the non english characters from the string and get the resultant string which contains only english characters. How can i do so ?
Imtiaz
Do you want to have only alphabetic characters? Or do you also want digits and symbols too?
-
Do you want to have only alphabetic characters? Or do you also want digits and symbols too?
I want digit numbers too.
Imtiaz
-
I want digit numbers too.
Imtiaz
I would check for characters between ' ' (SPACE) and '~' (TILDE). You may also be able to use a Regular Expression to remove the characters you don't want, but I've never done it that way.
-
MarkBrock wrote:
Convert each character into a byte
That seems unnecessary, as does the casting to int. If you want to do it that way, just use
if ( ( c >= 'A' ...