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. Visual Basic
  4. Gleaning a specific part out of a string

Gleaning a specific part out of a string

Scheduled Pinned Locked Moved Visual Basic
data-structureshelpquestion
2 Posts 2 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.
  • C Offline
    C Offline
    ccandler
    wrote on last edited by
    #1

    I am working on trying to get a specific part out of an array element and making a descision based on what number is presented. The number is 10 decimal digits long before conversion to hex. Once it is converted to hex the upper four numbers are the key to what get done next. How do you get the four upper bits out of a string and then determine what they are in a case statement? The following is what I have for the function so far Function manipdata() As Integer 'Look at the 3rd and 4th values from each array and determine what type of data it is and display it 'to the user in some format. Dim i As Integer = 1 Dim a As Boolean Dim b As String Do While i < icount b = Hex(son(i).data) a = b.StartsWith("1708") If a = True Then MessageBox.Show("You found a fwd one") End If 'MessageBox.Show("You found an aft one") 'Case "0812" ' MessageBox.Show("Go home") 'end case i = i + 1 Loop End Function Thanks and any help would be appreciated.

    D 1 Reply Last reply
    0
    • C ccandler

      I am working on trying to get a specific part out of an array element and making a descision based on what number is presented. The number is 10 decimal digits long before conversion to hex. Once it is converted to hex the upper four numbers are the key to what get done next. How do you get the four upper bits out of a string and then determine what they are in a case statement? The following is what I have for the function so far Function manipdata() As Integer 'Look at the 3rd and 4th values from each array and determine what type of data it is and display it 'to the user in some format. Dim i As Integer = 1 Dim a As Boolean Dim b As String Do While i < icount b = Hex(son(i).data) a = b.StartsWith("1708") If a = True Then MessageBox.Show("You found a fwd one") End If 'MessageBox.Show("You found an aft one") 'Case "0812" ' MessageBox.Show("Go home") 'end case i = i + 1 Loop End Function Thanks and any help would be appreciated.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Your description seems be a little vague and the code sample doesn't make much sense either, but we'll try this. What I think your doing is looking at the first four hex characters, or 3rd and 4th characters only (?) and doing some processing base on what you find. I THINK(!) your looking for something like this: (This example will look at the 3rd and 4th characters only!: ie. 17_08_)

      Dim i As Integer = 1
      Dim b As String
      
      Do While i < icount
      '  Grab the 3rd and 4th characters of the Hex code.
      '  This assumes that the Hex code is ALWAYS 4 digits long!
      b = Hex(son(i).data).ToString().SubString(3, 2)
      
      Select b
          Case "08"
              MessageBox.Show("You found a fwd one")
          Case "12"
              MessageBox.Show("Go Home")
          Case Else
              MessageBox.Show("Unknown code found: " & b)
      End Select
      

      Remember that Hex will NOT return a value padded with 0's on the left. An integer (15) converted to hex will return F, not 000F. So this method will NOT work in all cases. There may be a better method for making this determination, but it depends ENTIRELY on the data that you have in son().data. RageInTheMachine9532

      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