File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes hex string to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "hex string to string" Watch "hex string to string" New topic

hex string to string

Tyler Jordan
Ranch Hand

Joined: Nov 17, 2003
Posts: 70
I've been pulling my hair out trying to get the following code to work. My problem has been I need to compare a string of values with a hexadecimal value. What I decided to do was break out the string using chars and then reassemble it into a string. The problem is my conditional will not declare the two strings as the same, even though when I println them out, they are. If I create a string and compare it works. Is there some other way to get the literal value of oidValue? You will notice I only want the first 8 chars. Any help is appreciated!
oidValue is a hex string it was converted using toHexString()
oidValue = 00 01 30 1e e7 e0

newstring exits the for loop = 000130
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
Maybe you want to try
Tyler Jordan
Ranch Hand

Joined: Nov 17, 2003
Posts: 70
Thanks! Your idea worked. I found another way that uses the regionMatches() method. However, this method isn't nearly as clean as your way.
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
This is important...
Do you understand why using an equal sign for comparing two String objects didn't work, but using the method equals() did?
Just in case, I'm going to explain it.
When using an equal sign operator to compare two Strings you are not checking to see it they are the same from a textual content perspective. You are actually checking to see if they are the same instance of a String object. The only way you would ever get it to say they were equal would be to compare a String object instance to itself!
The default equals() method for String actually compares the textual content, which is what most of us ussually want to do when comparing Strings.
This is a very common mistake made by programmers when they start with Java, especially if they have programmed in other more permissive languages.
Hope this helps clarify why it works...

Byron Estes<br />Sun Certified Enterprise Architect<br />Senior Consulant<br />Blackwell Consulting Services<br />Chicago, IL<br /><a href="" target="_blank" rel="nofollow"></a>
subject: hex string to string
It's not a secret anymore!