stringTokenizer
I'm using a StringTokenizer to separate a list of filenames and id's(based on ";") that I get back from a database. My System.out.println looks like below
Results Before stringTokenizer: testfile.txt,78;testfile2.txt,79;testfile3.txt,80;textfile4.txt,81
Results After stringTokenizer:
testfile.txt, 78
testfile2.txt, 79
testfile3.txt, 80
testfile4.txt, 81
What I want to do next is the use a method that I have to rename each filename and fileid (the method adds the same character to the front of each) without having to hardcode each filename and id. Is there a way to do that for each line that i get back from the tokenizer?
String s="testfile.txt,78;testfile2.txt,79;testfile3.txt,80;textfile4.txt,81";String [] array=s.split(";");And now you have an array to do your changes... :)
that sounds like it could work....how could i do that. maybe i could show you the method that i am using
DirIO do = new DirO("filename","location","fileid","/");
do.makeVis();
the location and the last "/" will always be the same, put i want to add the filename and fileid based on each line i get back from my tokenizer
> that sounds like it could work....how could i do
> that. maybe i could show you the method that i am
> using
>
> DirIO do = new
> DirO("filename","location","fileid","/");
> do.makeVis();
>
> the location and the last "/" will always be the
> same, put i want to add the filename and fileid based
> on each line i get back from my tokenizer
I don't know where that DirO object came from, but this is how the split method works:
String text = "testfile.txt,78;testfile2.txt,79;testfile3.txt,80;textfile4.txt,81";
String array[] = text.split(",|;");
if(array.length%2 != 0)
throw new RuntimeException("array has an uneven number of elements!");
for(int i = 0; i < array.length-1; i+=2) {
System.out.println("file="+array[i]+", id="+array[i+1]);
}