illegal characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    illegal characters

    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.
  • Wayne

    #2
    Re: illegal characters

    (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

    "Dave" <Dave@discussio ns.microsoft.co m> wrote in message
    news:AD90B6C1-C1A2-4804-AD20-629ACB37DB1C@mi crosoft.com...[color=blue]
    > 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[/color]
    characters.[color=blue]
    > Is there an equivalent function to c# to chr() in Visual basic? I want[/color]
    the[color=blue]
    > 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.[/color]


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: illegal characters

      Dave <Dave@discussio ns.microsoft.co m> wrote:[color=blue]
      > 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.[/color]

      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

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Ahmed Qurashi

        #4
        Re: illegal characters

        C# equivalents of VB functions:

        int Asc(char ch)
        {
        //Return the character value of the given character
        return (int)Encoding.A SCII.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

        "Dave" <Dave@discussio ns.microsoft.co m> wrote in message
        news:AD90B6C1-C1A2-4804-AD20-629ACB37DB1C@mi crosoft.com...[color=blue]
        > 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[/color]
        characters.[color=blue]
        > Is there an equivalent function to c# to chr() in Visual basic? I want[/color]
        the[color=blue]
        > 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.[/color]


        Comment

        • Sunny

          #5
          Re: illegal characters

          In article <AD90B6C1-C1A2-4804-AD20-629ACB37DB1C@mi crosoft.com>,
          Dave@discussion s.microsoft.com says...[color=blue]
          > 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.
          >[/color]

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

          Sunny

          Comment

          • robkit

            #6
            RE: illegal characters

            I would suggest you to use Char class'es static methods like Char.IsLetter()
            or Char.IsLetterOr Digit() 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.

            "Dave" wrote:
            [color=blue]
            > 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.[/color]

            Comment

            Working...