Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

character escape question...help plz..  RSS feed

 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,i am using a file dialog in my application and by using the function getDirectory i get a string specifying the directory path of the selected file like say "c:\dirname\"..now i want to convert this string to "c:\\dirname\\"..how do i do it..because "\" is not a string, its a character,first of all i dont understand if its not a string then how come the getDirectory function returns it as a part of a string..please help..
regards
karan
 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fileDialog return a string which contains "\", where JVM takes care of the escapesequence. so u can use the same string for any manipulation.
I would like to know what purpose u want to convert "\" to "\\".
same prog:
public static void main(String arg[])
{
String fileDialogString = arg[0];
String tempString ="";
System.out.println("Given string :"+ fileDialogString);
for(int count=0;count<fileDialogString.length();count++) {>
if(fileDialogString.charAt(count) == '\\')
tempString = tempString+"\\"+"\\";
else
tempString = tempString+fileDialogString.charAt(count);
}
fileDialogString =tempString.trim();
System.out.println("Converted string :"+ fileDialogString);
}
if u try to convert it then physicall you have two "\" .
 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry..... Ignore the above code
public static void main(String arg[])
{
String fileDialogString = arg[0];
String tempString ="";
for(int count=0;count<fileDialogString.length();count++)>
{
if(fileDialogString.charAt(count) == '\\')
tempString = tempString+"\\"+"\\";
else
tempString = tempString+fileDialogString.charAt(count);
}
fileDialogString =tempString.trim();
}


 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry , once again the display for the for loop has corrupted
replace for loop by
count = 0; count is less than fileDialogString.length ;count++
ie
for(int count=0;count<fileDialogString.length();count++) >
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!