aspose file tools
The moose likes Beginning Java and the fly likes Splitting a string in 2 and turning it into hexadecimcal Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Splitting a string in 2 and turning it into hexadecimcal" Watch "Splitting a string in 2 and turning it into hexadecimcal" New topic
Author

Splitting a string in 2 and turning it into hexadecimcal

Iain Emsley
Ranch Hand

Joined: Oct 11, 2007
Posts: 60
Hi,

I'm trying to port some Perl code into Java for a web app which requires cookies for authentication. The code that I'm trying to port is:


I'm trying to put the cookie into a string and then split it. Being more used to Perl (as I'm learning Java on the job), I've come into difficulties with splitting the cookie into variables e and p. I've tried to set up a
code block to take e and then use int.to Hex to turn it into hexadecimal. Ultimately the two strings, e and p, need to go into a hash to be checked for validity but I'll cross that bridge once I arrive at it.


I think that I've become lost following my own footsteps and would be grateful for some guidance further through the forest. I think I'm trying to do too much too quickly in regards to the processes and perhaps need to break them down further?

Ultimately I'm wanting to use this in a servlet as part of the authentication process in Tomcat.

Yours,

Iain
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32606
    
    4
Welcome to the Ranch. I can only help a bit. You don't tell us which format the cookie text is in.
The line beginning for appears to be correct, but you need {} around the lines you wish to repeat. Otherwise you will only repeat the line in () with .equals("WALOGIN"). I think that line ought to have begun with if before the (.

By split, do you mean the split() method of the String class? If the text of the xookie is stored in the String you call xookie, you would invoke it with something like thisI think you will need to escape the hyphen which is a metacharacter in regular expressions, like this "\\-" in the regex String.

I am afraid I don't understand the bit about changing to hex; maybe somebody else can help. Or maybe if you explain it more fully . . .

Please try that lot and see whether that makes any difference. Try the splitting bit on its own, without the hex bit, see whether that works, then post again.

CR

There is a problem with posting here that it requires the word xookie be spelt wrongly. :roll:
Iain Emsley
Ranch Hand

Joined: Oct 11, 2007
Posts: 60
Campbell,

Many thanks for the advice. I'll try this (once I've got rid of another bug) and let you know how I get on with it.

Iain
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Splitting a string in 2 and turning it into hexadecimcal
 
Similar Threads
Mapping Unicode to Ascii for web applications
Converting special characters to hex code
Replicating a string?
To Hex String and back...
Hexadecimal and decimal convert code