This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hex string to string

 
Tyler Jordan
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 348
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you want to try
 
Tyler Jordan
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 313
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic