There are just some things that google can never tell you, and no matter how hard you try to search for it you may never find what you are looking for. That happened to me when I tried to find out how to convert a String to an Integer array in Java. So, here’s the simple function that will do this:
1 2 3 4 5 6 7 8 9 | public static int[] strToInt (String inp) { int[] toRet = new int[inp.length()]; int i = 0; while(i < inp.length()) { toRet[i]=(int)inp.charAt(i); i++; } return toRet; } |
This function goes through every character of the string and gets the integer value of the character and adds it to the integer array. When it’s done adding everything, it returns the integer array with the same length as the string.
(PS: Sorry for unindented code; I’ll have to find a better code plugin..)


June 17th, 2009 at 10:50 pm
OMG, LERN2FOR!
June 17th, 2009 at 11:50 pm
Haha, I would learn 2 for, but I don’t feel like it and I like wasting lines of code =D. While loops work for me, I’ve been using them for years, I like wasting lines of code, and I may or may not be mentally challenged in certain areas.