Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. String and non english characters

String and non english characters

Scheduled Pinned Locked Moved C#
questionbusiness
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Imtiaz Murtaza
    wrote on last edited by
    #1

    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

    M P 2 Replies Last reply
    0
    • I Imtiaz Murtaza

      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

      M Offline
      M Offline
      MarkB777
      wrote on last edited by
      #2

      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

      P 1 Reply Last reply
      0
      • M MarkB777

        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

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        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' ...

        M 1 Reply Last reply
        0
        • I Imtiaz Murtaza

          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

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Do you want to have only alphabetic characters? Or do you also want digits and symbols too?

          I 1 Reply Last reply
          0
          • P PIEBALDconsult

            Do you want to have only alphabetic characters? Or do you also want digits and symbols too?

            I Offline
            I Offline
            Imtiaz Murtaza
            wrote on last edited by
            #5

            I want digit numbers too.

            Imtiaz

            P 1 Reply Last reply
            0
            • I Imtiaz Murtaza

              I want digit numbers too.

              Imtiaz

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • P PIEBALDconsult

                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' ...

                M Offline
                M Offline
                MarkB777
                wrote on last edited by
                #7

                Your right :).

                Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups