Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Data Structures Getting There Object Inheritance

Aaron Leung
Aaron Leung
1,212 Points

Code Challenge: Escaping Double Quotes

Hi All,

2 questions: 1) For some reason my code outputs: "BlogPost: TITLE by AUTHOR" but my output is apparently wrong despite that the challenge asking for: "BlogPost: TITLE by AUTHOR". I have also tried returning my code without escaping double quotes. Can someone help me?

@Override
  public String toString() {
    return ("?BlogPost: " + mTitle.toUpperCase() + " by " +   mAuthor.toUpperCase() + "?").replace('?', '"');
  }

2) I would really appreciate if someone could suggest to me a better way to insert quotes at the start and end of a string. For some reason the way Craig escaped the double quotes does not work at the start & end of the string.

Thanks

1 Answer

Hi Aaron,

You've taken that challenge too literally. The output the challenge is looking for doesn't include the quotation marks or the capitalised member variables. It just wants:

  @Override
  public String toString() {
    return ("BlogPost: " + mTitle + " by " +   mAuthor);
  }

The quotation marks were just to demark the desirted output and the capitals were to indicate that the text should be amended to something in the challenge without giving the answer away!

I hope that helps.

Steve.

Aaron Leung
Aaron Leung
1,212 Points

Oops lol thank you very much!

Would you happen to know another way to include quotes at the start and end of a string?

I shall have a go now ... I thought the back-slash worked OK as an escape character - is that not working for you generally or just on this task?

I just created a short program in Java:

import java.io.*;

public class escape{
  public static void main(String[] args) {
        System.out.println("This is \"in\" quotations");
        System.out.println("\"This\" is also in quotations");
  } 
}

All this does is print out This is "in" quotations then "This" is also in quotations... and it works fine. What problems are you having?

Steve.