replace \ with \\

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kiransasi
    New Member
    • Sep 2007
    • 5

    #1

    replace \ with \\

    Hi all!

    I want a java function which replaces the char \ with a string \\.
    my actual requirement is to convert a url like

    C:\xyz abc\1234\def\

    to

    C:\\xyz\abc\\12 34\\def\\
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by kiransasi
    Hi all!

    I want a java function which replaces the char \ with a string \\.
    my actual requirement is to convert a url like

    C:\xyz abc\1234\def\

    to

    C:\\xyz\abc\\12 34\\def\\
    I think you are looking for a URI in windows directory, right? :-)
    Then you need not to do that.
    Windows supports X:\abc\def\ghi. jkl

    [code=java]
    File file = new File("X:\abc\de f\ghi.jkl");
    //it is not valid due to invalid escape sequence.
    //then you will need to do like this ............
    File file = new File("X:\\abc\\ def\g\hi.jkl");
    //it is now valid
    File file = new File("X:/abc/def/ghi.jkl");
    //it is also valid
    [/code]

    So you got my point buddy ? :-)

    Debasis Jana

    Comment

    • kiransasi
      New Member
      • Sep 2007
      • 5

      #3
      Thanks for the reply!

      but my problem is:

      Actually i am using a FileDialog box from which the user selects a file
      and i am using FileDialog box's getDirectory method...and it will return
      the path of the file selected in the form of
      D:\xyz abc\1234\

      but i have to send the url to the server in the form of

      D:\\xyz\abc\\12 34\\

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by kiransasi
        Thanks for the reply!

        but my problem is:

        Actually i am using a FileDialog box from which the user selects a file
        and i am using FileDialog box's getDirectory method...and it will return
        the path of the file selected in the form of
        D:\xyz abc\1234\

        but i have to send the url to the server in the form of

        D:\\xyz\abc\\12 34\\
        Open the API docs page for the String class and pick your required method.

        Comment

        Working...