Transform non english words to a unique representation
-
Hello everybody, I need a method in c# to transform non english word to a unique string representation. The method should detect if the word contains non english characters and, only in that case it converts the word to diffrent representation, the algo is the following:
String transformString(String inputString)
{
if(inputString.containsNonEnglishChar())
{
String res = "";
foreach(char ch in inputString)
{
res += transformChar(ch);
}
return res;
}
return inputString;// return the word as is
}I can write the method my way, but I prefer to find something standard, like base 64 or URL encoding or something famous. Thanks in advance.
HZ
-
Hello everybody, I need a method in c# to transform non english word to a unique string representation. The method should detect if the word contains non english characters and, only in that case it converts the word to diffrent representation, the algo is the following:
String transformString(String inputString)
{
if(inputString.containsNonEnglishChar())
{
String res = "";
foreach(char ch in inputString)
{
res += transformChar(ch);
}
return res;
}
return inputString;// return the word as is
}I can write the method my way, but I prefer to find something standard, like base 64 or URL encoding or something famous. Thanks in advance.
HZ
The System.Char structure [^] has some properties like
IsLetter
. Probably there are similar functions that are culture aware, for which you basically pass some English culture (e.g. "en-US") and then call "IsLetter
" and get atrue
/false
if it is or not.• My personal 24/7 webcam • Zeta Test - Intuitive, competitive Test Management environment for Test Plans and Test Cases. Download now! • Zeta Producer Desktop CMS - Intuitive, very easy to use. Download now!
-
The System.Char structure [^] has some properties like
IsLetter
. Probably there are similar functions that are culture aware, for which you basically pass some English culture (e.g. "en-US") and then call "IsLetter
" and get atrue
/false
if it is or not.• My personal 24/7 webcam • Zeta Test - Intuitive, competitive Test Management environment for Test Plans and Test Cases. Download now! • Zeta Producer Desktop CMS - Intuitive, very easy to use. Download now!
Thanks man, I can know if a char is in the ASCII range, I can do this: if((int)ch <= 255), and this is sufficient in my case, but I try to find a better way to encode the string like the url format. As Does the HttpServerUtility.UrlEncode method. But I cannot add a reference to the System.web namespace, I have to find some alternative. Thanks for your advice.
HZ
-
Thanks man, I can know if a char is in the ASCII range, I can do this: if((int)ch <= 255), and this is sufficient in my case, but I try to find a better way to encode the string like the url format. As Does the HttpServerUtility.UrlEncode method. But I cannot add a reference to the System.web namespace, I have to find some alternative. Thanks for your advice.
HZ
HZ_79 wrote:
I cannot add a reference to the System.web namespace
Why is it so? just do: Solution Pane/Add Reference/.NET/System.Web then insert a using statement. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hello everybody, I need a method in c# to transform non english word to a unique string representation. The method should detect if the word contains non english characters and, only in that case it converts the word to diffrent representation, the algo is the following:
String transformString(String inputString)
{
if(inputString.containsNonEnglishChar())
{
String res = "";
foreach(char ch in inputString)
{
res += transformChar(ch);
}
return res;
}
return inputString;// return the word as is
}I can write the method my way, but I prefer to find something standard, like base 64 or URL encoding or something famous. Thanks in advance.
HZ