This message was edited by stricks at 2005-6-27 11:6:59
This message was edited by stricks at 2005-6-27 6:24:7
I have a String that consists of, "C:\My Stuff\Cool\ok.txt".
How can I first convert that into a string and then whenever there is a a '\' character, add another one?
Actually, I can convert, I think, I just need help with the '\'.
This is how I was trying to do it
public static String addSlash(String file){
char[] finshed_pathname, orginal_pathname;
int length = file.length();
orginal_pathname = new char[length];
file.getChars(0,length,orginal_pathname, 0);
System.out.println(length);
// Get teh length for the finishedFile array
for(int i = 0 ; i < orginal_pathname.length ; i++){
if(orginal_pathname[i] == '\\'){
length++;
}
System.out.print(orginal_pathname[i]);
}
System.out.println();
System.out.println(length);
finshed_pathname = new char[length];
for(int i = 0, j=0 ; i < orginal_pathname.length ; i++){
finshed_pathname[j] = orginal_pathname[i];
System.out.print(finshed_pathname[j]);
if(orginal_pathname[i] == '\\'){
j++;
finshed_pathname[j] = '\\';
System.out.print(finshed_pathname[j]);
}
}
System.out.println();
file = new String(finshed_pathname);
return file;
}
Generates : \\\\\t...................................
BUT, the out.prints in the for loop creates this:
C:\\Documents and Settings\\stricbr3\\Desktop\\Info\\Q&A.txt
What am I doing wrong?
Thanks