Results 1 to 8 of 8
  1. #1
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default Problem with String encodings

    Hi,

    I have problems encoding Strings ,actually i am not good in encoding concept.
    Actually what my requirement is to save exact file path of file something like
    E:\temp in my sql database .Everything is fine except "\t" is saving like
    "E: emp" "E:\temp " .please give me some idea to solve this problem.

    Regarding
    Sandeep

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,042
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by sandeepsai39 View Post
    Hi,

    I have problems encoding Strings ,actually i am not good in encoding concept.
    Actually what my requirement is to save exact file path of file something like
    E:\temp in my sql database .Everything is fine except "\t" is saving like
    "E: emp" "E:\temp " .please give me some idea to solve this problem.
    If the "E:\temp" String is a literal String, the compiler treats \t as a tab character; escape the behaviour of the \ by doubling it, e.g. "E:\\temp", or by using the forward slash: "E:/temp".

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    6

    Default

    Try
    Java Code:
    "E:\\temp"
    or use backslash
    Java Code:
    "E:/temp"

  4. #4
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    Thank u for quick reply.
    The solution you mentioned is goes well when i statically give file path some thing like "E:/temp" .
    Actually my requirement is user upload a file i save it in database with file path from where he is selecting the file.In this case case i don't know what exactly the location .The file location for user may contains some characters something like "\t" or "\n" or "\r" etc.. .In that case i can't use as you said.I need a some encoding concept to do this.Some thing like UTF-8 or Unicode encoding .I am not good in encoding . I am very great
    full to you if you help me

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,042
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by sandeepsai39 View Post
    Thank u for quick reply.
    The solution you mentioned is goes well when i statically give file path some thing like "E:/temp" .
    Actually my requirement is user upload a file i save it in database with file path from where he is selecting the file.In this case case i don't know what exactly the location .The file location for user may contains some characters something like "\t" or "\n" or "\r" etc.. .In that case i can't use as you said.I need a some encoding concept to do this.Some thing like UTF-8 or Unicode encoding .I am not good in encoding . I am very great
    full to you if you help me
    So there is some part in your software that translates, say, \t to a single tab character, right? If so, double all your \ characters if that software translates the character pair to a single \ character; otherwise find the translation rules of that piece of software because without them the question can't be answered.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  6. #6
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    Thanks JoasH,
    I already did what you said it goes well,but i am not looking for a only "\t" characters.I am looking for more robust code for all special characters ,may be in future i get situation where i need to store special characters(some thing like saving url where we have no of special characters).I am looking in that perspective . I just explained on example where i got problems in strings.Please consider in my point of view and if you have any ideas please suggest me.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,042
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by sandeepsai39 View Post
    Thanks JoasH,
    I already did what you said it goes well,but i am not looking for a only "\t" characters.I am looking for more robust code for all special characters ,may be in future i get situation where i need to store special characters(some thing like saving url where we have no of special characters).I am looking in that perspective . I just explained on example where i got problems in strings.Please consider in my point of view and if you have any ideas please suggest me.
    You could try to do this:
    Java Code:
    String encoded= decoded.replacAll("\\", "\\\\");
    This code snippet replaces each \ with two \\.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  8. #8
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    Thanks for reply.Is it work for all type of possible characters that come in url.

Similar Threads

  1. String problem: deleting
    By BlueBird in forum New To Java
    Replies: 3
    Last Post: 03-18-2011, 06:21 AM
  2. string and condition problem
    By durdanto in forum New To Java
    Replies: 1
    Last Post: 02-17-2011, 09:20 AM
  3. Replies: 6
    Last Post: 12-06-2010, 10:26 AM
  4. File encodings
    By JL4 in forum New To Java
    Replies: 3
    Last Post: 11-23-2008, 06:09 PM
  5. String Problem
    By gnomewise in forum New To Java
    Replies: 1
    Last Post: 10-19-2008, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •