Results 1 to 6 of 6

Thread: string manipulation

  1. #1

    Thread Starter
    Lively Member meander's Avatar
    Join Date
    Jun 2004
    Posts
    121

    string manipulation

    can you do the hex() thing in vb? i know you can in qbasic, and that will return the ascii hex value of the string in the parentheses correct?

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    hex() in VB will take a number and convert it to hex. to convert a string to hex, you would need to loop through each character and get the ascii value, then use hex on that.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Or just use my AscToHex function:

    http://www.vbforums.com/showthread.p...hreadid=292448


  4. #4

    Thread Starter
    Lively Member meander's Avatar
    Join Date
    Jun 2004
    Posts
    121
    ok, how do you get the ascii value?
    an looping through the string i can do it in qbasic, but how would you do it in vb?

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    You can take a look at digitalerror's code he linked to. But doing it the most normal (slow) way:

    VB Code:
    1. Dim A As Integer, Temp As String
    2.  
    3. 'if we had textbox Text1 with some text...
    4. For A = 1 To Len(Text1.Text)
    5.     Temp = Temp & " " & Hex$(Asc(Mid$(Text1.Text, A, 1)))
    6. Next A
    7.  
    8. Text2.Text = Temp

    So you get a single character with Mid$, then give it to Asc, and then Hex$ turns it to a hexadecimal. And it is included in to the string Temp which is displayed in textbox Text2.

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    A note when you convert using Hex(). The result may be only a single character.

    Something like...

    TmpChr = hex(asc(mid$(string,x,1))) 'w/e
    strReturn = strReturn & string(2-len(tmpChr)) & tmpchr

    But my method is MUCH faster. The memory is much more quickly allocated with the byte arrays. And avoiding strings for the actual processing(strings are SLOW... yet flexible).

    I figure my method should be able to handle... on my system... atleast 30 MB/s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width