Results 1 to 3 of 3
  1. #1
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    174
    Rep Power
    0

    Default Reading in string with "s, \s, and 's

    Hey.

    Input:
    String s = "this isn't a normal problem - it's a bit "weird," to say the least\most";

    How would I get my program to read this as all one string.

    BEFORE YOU TELL ME TO USE AN ESCAPE CHARACTER, the input is going to be long - 10000 characters+, and will be coming from a text file.

    I need a non-manual way to do it.

    Of course, the first thing that came to mind was simply searching through the string until I find a "weird" character and adding a \ in front of it- but I can't do that, if it isn't even seen as a string!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Reading in string with "s, \s, and 's

    How would I get my program to read this as all one string.
    Read the bytes into a byte array and convert that to a String.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Reading in string with "s, \s, and 's

    You could also use FileReader. But whatever method you use I suggest you use StringBuilder whenever possible. It is a mutable class and is much more efficient than String when making changes to sequences of characters.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  2. Replies: 1
    Last Post: 05-07-2012, 05:35 PM
  3. Replies: 14
    Last Post: 04-08-2011, 06:01 PM
  4. Replies: 10
    Last Post: 12-07-2010, 12:29 PM
  5. Replies: 0
    Last Post: 04-02-2009, 07:02 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
  •