Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Detecting HEX

Posted on 2008-10-10
Medium Priority
609 Views
How can I detect whether a string contains HEX or not?
0
Question by:kevp75
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 4

Expert Comment

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

ID: 22690321
no limitations
0

LVL 4

Accepted Solution

rhodesb earned 2000 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>")

%>
``````
0

LVL 25

Author Closing Comment

ID: 31505067
you got it, thanks
0

## Featured Post

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
###### Suggested Courses
Course of the Month12 days, 6 hours left to enroll