Possible Duplicate:
How do I split strings in J2ME?
I have a String data which is like csv , that is there are “;” inside the String data. But in my case there is always a “;” at the end of the String. I want to create a method which gives a String at a certain number from this csv. For example :
String csv = "145557;123456789012;Michael Robert;1000000;200000;;12/05/2011;;" ;
In this String there are 8 “columns“. I say “column” the data between two “;” ( the first column is not enclosed by two “;” but only the one at its right ).
In this example the data “Michael Robert” has the number 2 ( or 3 if we start at 1 for the first column ).
So how to get the data ( column ) at a specified number ?
NB : I use Java ME
In J2ME you can write a method like this:
UPDATE: By the way, due to the way that
substringis implemented it is better toreturn new String(csv.substring(fromIndex, toIndex));, otherwise the substring will hold a reference to the original string and then as long as the substring is not GC-able, the original String won’t be GC-able as well.