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. Returning Random Unicode Characters

Returning Random Unicode Characters

Scheduled Pinned Locked Moved C#
8 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.
  • M Offline
    M Offline
    Mustafa Ismail Mustafa
    wrote on last edited by
    #1

    I'm having a bit of a problem getting the Unicode version of this:

    ((char)((int)'a' + new Random().Next(26))).ToString();

    The above snippet returns a random lowercase character. I'm trying to do the same thing for Unicode Characters in the range of 0621 - 064A Suggestions?

    If the post was helpful, please vote!


    Why won't the worm just leave me be?

    D 1 Reply Last reply
    0
    • M Mustafa Ismail Mustafa

      I'm having a bit of a problem getting the Unicode version of this:

      ((char)((int)'a' + new Random().Next(26))).ToString();

      The above snippet returns a random lowercase character. I'm trying to do the same thing for Unicode Characters in the range of 0621 - 064A Suggestions?

      If the post was helpful, please vote!


      Why won't the worm just leave me be?

      D Offline
      D Offline
      Dominik Reichl
      wrote on last edited by
      #2

      ((char)((new Random()).Next(0x621, 0x64A + 1))).ToString();

      :~


      Too many passwords to remember? Try KeePass Password Safe!

      M 1 Reply Last reply
      0
      • D Dominik Reichl

        ((char)((new Random()).Next(0x621, 0x64A + 1))).ToString();

        :~


        Too many passwords to remember? Try KeePass Password Safe!

        M Offline
        M Offline
        Mustafa Ismail Mustafa
        wrote on last edited by
        #3

        Same problem. The problem being char apparently doesn't cover the letters I want to it simply returns a "?" Thanks though

        If the post was helpful, please vote!


        Why won't the worm just leave me be?

        A 1 Reply Last reply
        0
        • M Mustafa Ismail Mustafa

          Same problem. The problem being char apparently doesn't cover the letters I want to it simply returns a "?" Thanks though

          If the post was helpful, please vote!


          Why won't the worm just leave me be?

          A Offline
          A Offline
          Alan Balkany
          wrote on last edited by
          #4

          A wild guess: Maybe the Unicode char is in a font you don't have installed.

          M 1 Reply Last reply
          0
          • A Alan Balkany

            A wild guess: Maybe the Unicode char is in a font you don't have installed.

            M Offline
            M Offline
            Mustafa Ismail Mustafa
            wrote on last edited by
            #5

            Nope, Arabic would be a staple of my system being as about 80% of my work is in Arabic (front end) :) The problem is that whenever I try to cast the numeric unicode value of the char seems to "truncate" it which is very strange considering char is a unicode character.

            If the post was helpful, please vote!


            Why won't the worm just leave me be?

            A 1 Reply Last reply
            0
            • M Mustafa Ismail Mustafa

              Nope, Arabic would be a staple of my system being as about 80% of my work is in Arabic (front end) :) The problem is that whenever I try to cast the numeric unicode value of the char seems to "truncate" it which is very strange considering char is a unicode character.

              If the post was helpful, please vote!


              Why won't the worm just leave me be?

              A Offline
              A Offline
              Alan Balkany
              wrote on last edited by
              #6

              Maybe changing the encoding might give a different result. UTF-8 uses one byte for the range 0-127, but more bytes for other character sets. UTF-16 uses two bytes for all characters, but is limited to the Basic Multilingual Plane (BMP). The BMP covers most modern languages, including Arabic I'm sure.

              M 1 Reply Last reply
              0
              • A Alan Balkany

                Maybe changing the encoding might give a different result. UTF-8 uses one byte for the range 0-127, but more bytes for other character sets. UTF-16 uses two bytes for all characters, but is limited to the Basic Multilingual Plane (BMP). The BMP covers most modern languages, including Arabic I'm sure.

                M Offline
                M Offline
                Mustafa Ismail Mustafa
                wrote on last edited by
                #7

                Snippet please?

                If the post was helpful, please vote!


                Why won't the worm just leave me be?

                A 1 Reply Last reply
                0
                • M Mustafa Ismail Mustafa

                  Snippet please?

                  If the post was helpful, please vote!


                  Why won't the worm just leave me be?

                  A Offline
                  A Offline
                  Alan Balkany
                  wrote on last edited by
                  #8

                  I'm not sure if this will help with your problem, but here's a link to examples that uses encodings with conversions: http://msdn.microsoft.com/en-us/library/system.text.encoding.convert(VS.71).aspx[^] The Encoding class supports multiple Unicode encodings, and I was hypothesizing that the wrong one could have given the symptoms you're seeing.

                  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