Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.