illegal characters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to cut out illegal characters in a string submitted from a mobile
phone to a web form. I need a way to check for the illegal characters in a
textbox. I intend to loop through the text and remove the illegal characters.
Is there an equivalent function to c# to chr() in Visual basic? I want the
decimal value of a character, like "A" is 65 in ACII2. If there is a
equilvalent command does it return ACII2 or unicode?

I know there is a chr command in c# but it dosen't do the same thing.
 
Dave said:
I need to cut out illegal characters in a string submitted from a mobile
phone to a web form. I need a way to check for the illegal characters in a
textbox. I intend to loop through the text and remove the illegal characters.
Is there an equivalent function to c# to chr() in Visual basic? I want the
decimal value of a character, like "A" is 65 in ACII2. If there is a
equilvalent command does it return ACII2 or unicode?

I know there is a chr command in c# but it dosen't do the same thing.

There's no "chr" command (or any commands) in C#. However, you can just
use the unicode value:

int x = 'A'; // x will now be 65
 
(int)'A' will give you 65

so

char temp = 'A';
(int) temp

or

(int)stringVar[x]


--
Thanks
Wayne Sepega
Jacksonville, Fl


"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 
C# equivalents of VB functions:

int Asc(char ch)
{
//Return the character value of the given character
return (int)Encoding.ASCII.GetBytes(S)[0];
}

Char Chr(int i)
{
//Return the character of the given character value
return Convert.ToChar(i);
}


There are also some nice builtin methods for string handling in c# such as
Replace(), Split() and Remove().

See docs for more details.

ok,
aq
 
I need to cut out illegal characters in a string submitted from a mobile
phone to a web form. I need a way to check for the illegal characters in a
textbox. I intend to loop through the text and remove the illegal characters.
Is there an equivalent function to c# to chr() in Visual basic? I want the
decimal value of a character, like "A" is 65 in ACII2. If there is a
equilvalent command does it return ACII2 or unicode?

I know there is a chr command in c# but it dosen't do the same thing.

In addition to the other answers, you can use regular expressions to
remove the illegal characters.

Sunny
 
I would suggest you to use Char class'es static methods like Char.IsLetter()
or Char.IsLetterOrDigit() as they take in account the language support. For
example if you run your application in US 'ä' would be an illegal character
but in Denmark it will be OK. Char methods take care of it you you.
 
Back
Top