• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

character escape sequence question..urgent..

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 atring..please help..
regards
karan
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i has used this long back (a JFileChooser).
am just pasting the part of the code that gets u the full file name.Just see if it's of some help to you.
It can be directly used to open a file selected. I remeber having used it with a FileInputStream constructor.
if (fileChooser.showSaveDialog(local) ==
JFileChooser.APPROVE_OPTION){
fileName = fileChooser.getSelectedFile().toString);
}

karthik.
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi karthik,
i actually dont need a code to open a file,i already did so,what i need is to change "c:\dir\" to "c:\\dir\\"..please tell me how to do this..
regards
karan
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Karan,
see if this can be of any help to you.
This is the code i wrote to convert the string like the one you have to the one u require.
//Code starts
import java.io.*;
import java.util.*;
public class A{
public static void main(String sr[]){
Properties prop=System.getProperties();
String value=prop.getProperty("user.home");
System.out.println("Value before : "+value );
StringBuffer sb= new StringBuffer () ;
for(int i = 0;i < value.length(); i++) {
char c=value.charAt(i);
String s=""+c;
if(s.trim().equals("\\")){
sb=sb.append('\\');
sb=sb.append('\\');
}else{
sb=sb.append(c);
}
}
value=sb.toString();
System.out.println("Value afer : "+value );
}
}
// code ends
This is the out put i got.
//Output
Value before : C:\WINNT\Profiles\soak
Value afer : C:\\WINNT\\Profiles\\soak
Tool completed successfully
//output
U can replace the String value by yours.
Isn't this what u wanted??
please let me know .. if i can help u more.
-sid
[This message has been edited by Siddharth Oak (edited July 19, 2001).]
[This message has been edited by Jim Yingst (edited July 19, 2001).]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sid- you needed a space after the < in your for statement. Otherwise our messaging software thinks you're starting an HTML tag, and tries to interpret your code rather than display it. I inserted the space for you.
 
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sid,
thanks for the reply,i actually figured it out myself using substrings..but thanks a lot anyways for ur help..
regards
karan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic