Hi All,
I have to left-pad a string with zeroes. I tried using String.format but it gives me an error. I have looked at a similar thread [here |http://forums.sun.com/thread.jspa?forumID=54&threadID=5374247] but that deals with integer type and not string type.
I think the error I am getting is because String.format tries to add ZEROes to an integer type and not String. I cannot do a Integer.parseInt(myString) as myString is in Hexadecimal notation. Please help me figure this one out.
In a nutshell:
My existing Hex string: ffe
The string I require: 00000ffe
Here is my code:
public String padLeft (String myString, int n)
{
myString=String.format("%0"+n+"x",myString);
return myString;
}
What am I doing incorrectly?