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

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


    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
    Eastern Florida
    Rep Power

    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
    Northern Virginia, United States
    Rep Power

    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.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on 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