Solved

Detecting HEX

Posted on 2008-10-10
4
602 Views
Last Modified: 2012-05-05
How can I detect whether a string contains HEX or not?
0
Comment
Question by:kevp75
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:rhodesb
ID: 22690240
Is there a limited number of things that could be in the string?  For example, is the string any alphabetic letters or just hex letters or is it decimal numbers and/or hex letters?  I guess I'm trying to ask if there is any limitations on what is can possibly be in the string?  
Regular expressions are usually a good solution for this type of thing.  If you can let me know the specifics of what might be in the field, I can give you some regular expression code to find what you are looking for.
0
 
LVL 25

Author Comment

by:kevp75
ID: 22690321
no limitations
0
 
LVL 4

Accepted Solution

by:
rhodesb earned 500 total points
ID: 22690724
You didn't really answer my questions so I'll assume that the string can contain anything and the HEX that you are looking for will be its own word (have spaces on either side or be bounded by the start and/or end of the string) and will be similar to this format: 0x849AB9 where there is a 0 followed by an x followed by a group of hexidecimal digits (0-F).

This function will return a boolean true or false based on whether there is a HEX somewhere in the string or not.  How to use the function is illustrated below it.
Please explain in more detail if this is not what you are looking for.
<% 
' Input a string into strVal
' Returns boolean indicating if the string contains a hex value
Function containsHEX(strVal)
    Dim regExObj
    Set regExObj = New RegExp
    With regExObj
        .Pattern = "\b0[xX][0-9a-fA-F]+\b"
        .IgnoreCase = True
        .Global = True
    End With
 
    containsHEX = regExObj.Test(strVal)
    set regExObj = nothing
End Function
 
 
Dim testString1, testString2
 
testString1 = "qoe dlfoi aksfjp iel d,as"
testString2 = "wer 0x8AAF9"
 
response.Write("testString1 contains HEX: " & containsHEX(testString1) & "<br>")
response.Write("testString2 contains HEX: " & containsHEX(testString2) & "<br>")
 
%>

Open in new window

0
 
LVL 25

Author Closing Comment

by:kevp75
ID: 31505067
you got it, thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question