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. Web Development
  3. ASP.NET
  4. Generate GUID using 2 digit State Code

Generate GUID using 2 digit State Code

Scheduled Pinned Locked Moved ASP.NET
helpquestion
4 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.
  • A Offline
    A Offline
    AmitChampaneri
    wrote on last edited by
    #1

    I am getting problem in generating new GUID using its constructor who takes one string argument. like this Guid regionID = new Guid(this.State.SelectedValue); state gives 2 digit state code.The error says you need 32 digit with 4 dashes string to generate GUID. any solutions ? Amit Champaneri

    L C 2 Replies Last reply
    0
    • A AmitChampaneri

      I am getting problem in generating new GUID using its constructor who takes one string argument. like this Guid regionID = new Guid(this.State.SelectedValue); state gives 2 digit state code.The error says you need 32 digit with 4 dashes string to generate GUID. any solutions ? Amit Champaneri

      L Offline
      L Offline
      l0kke
      wrote on last edited by
      #2

      That's right, because GUID is basically 16 bytes separated in certain places by 4 dashes... You can not have GUID with only two bytes. If you want, you can do it like this: byte[] guidBytes = new byte[16]; Random rand = new Random(); rand.NextBytes(quidBytes); guidBites[0] = Convert.ToByte(this.State.SelectedValue[0]); guidBites[1] = Convert.ToByte(this.State.SelectedValue[1]); Guid myGuid = new Guid(guidBytes); this should works Pilo

      C 1 Reply Last reply
      0
      • A AmitChampaneri

        I am getting problem in generating new GUID using its constructor who takes one string argument. like this Guid regionID = new Guid(this.State.SelectedValue); state gives 2 digit state code.The error says you need 32 digit with 4 dashes string to generate GUID. any solutions ? Amit Champaneri

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        I think you are confused about what a GUID actually is. A Guid is a value that is generated by the system to be Globally (as in the world) unique. You should be able to generate as many guid values as you like on your machine and so could everyone else, but every value would always be unique.


        *** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog | Photos

        1 Reply Last reply
        0
        • L l0kke

          That's right, because GUID is basically 16 bytes separated in certain places by 4 dashes... You can not have GUID with only two bytes. If you want, you can do it like this: byte[] guidBytes = new byte[16]; Random rand = new Random(); rand.NextBytes(quidBytes); guidBites[0] = Convert.ToByte(this.State.SelectedValue[0]); guidBites[1] = Convert.ToByte(this.State.SelectedValue[1]); Guid myGuid = new Guid(guidBytes); this should works Pilo

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          This solution is really unlikely to help the OP because you have not taken into account what he might actually want a GUID for. You need to try to look at the bigger picture when answering questions because most are asking questions because they've got themselves in to a bit of confusion about something. Subsequently they may not ask the best question to get the answer they need.


          *** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog | Photos

          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