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

C# C# Basics Strings Escape Sequences

Elfar Oliver
Elfar Oliver
3,924 Points

I can't use the escape sequence for double quote or I just don't know where to input it. Maybe my return value is wrong

Program.cs
using System;

class Program
{

    static string Quote(string phrase)
    {
        return Quote;
    }

    static void Main(string[] args)
    {
        // Quote by Maya Angelou.
        Console.WriteLine(Quote("When you learn, teach. When you get, give."));
        // Quote by Benjamin Franklin.
        Console.WriteLine(Quote("No gains without pains."));
    }

}
Elfar Oliver
Elfar Oliver
3,924 Points

using System;

class Program {

static string Quote(string phrase)
{
    return \"Quote\"";
}

Any closer with that?

2 Answers

Steven Parker
Steven Parker
231,248 Points

Here's a few hints:

  • Quote is the name of the function, that's not what you need to return
  • the return value must be a string, and phrase will be part of it
  • you'll need to add a quote mark to the beginning and end of phrase
  • one of the ways to encode a quote mark is to escape it with backslash (example: "say \"Yay!\"")
Elfar Oliver
Elfar Oliver
3,924 Points

I'll just give up and move on. Thanks though

Steven Parker
Steven Parker
231,248 Points

It might be worth working it out.   "No gains without pains."   :wink:

Elfar Oliver
Elfar Oliver
3,924 Points

Tried it for at least 30mins just inputting anything I could think of and I was nowhere closer

Steven Parker
Steven Parker
231,248 Points

You got the escapes now, but still:

  • the surrounding quotes are imbalanced, you need one more at the beginning of the string
  • as I said before, Quote is the name of the function, it won't be part of what you return
  • phrase will be part of what you do return
  • to put quotes around the phrase, you could use concatenation or interpolation (if they've covered that?)
Elfar Oliver
Elfar Oliver
3,924 Points

Yeah, I'm no closer than before. I tried " and \ all over the place and used phrase like you suggested and your hints are helping me just as much as the hints in the assignment. This is like PokΓ©mon, can't catch 'em all

Steven Parker
Steven Parker
231,248 Points

You're learning a new skill .. so there will hurdles to cross, but it's worth staying with them. Show me what you've got so far, I'll bet you're pretty close now.

Elfar Oliver
Elfar Oliver
3,924 Points

using System;

class Program {

static string Quote(string phrase)
{
    return ""\"phrase"\"";
}

static void Main(string[] args)
{
    // Quote by Maya Angelou.
    Console.WriteLine(Quote("When you learn, teach. When you get, give."));
    // Quote by Benjamin Franklin.
    Console.WriteLine(Quote("No gains without pains."));
}

}

Elfar Oliver
Elfar Oliver
3,924 Points

I get where you're going with this hoping I'll get it and you'll get to "Attaboy" or whatever. But the problem with these assignments is they're unskippable and never supply the answer. If I'd have the answer I could compare that to what the objective is requesting instead of never getting it. It's so easy to understand the answer if you have it and learn from that

Steven Parker
Steven Parker
231,248 Points

I was right, you were nearly there. You just had one quote out of place and were missing the concatenation operators (+):

    return "\"" + phrase + "\"";
Elfar Oliver
Elfar Oliver
3,924 Points

I was never gonna get that because I don't even understand the placement of the ". They're not symmetrical and it's really confusing

return (")\"" + phrase + (")\"";

Are the " I put in brackets the actual quotes and the \"" are extra quotes? Making the return "\"" + phrase + "\""; a quote + quote + phrase + quote + quote?

Steven Parker
Steven Parker
231,248 Points

The "working" quotes (the ones defining strings) are symmetrical:

//          vv              vv   these are the escaped "data" quotes
    return "\"" + phrase + "\"";
//         ^  ^            ^  ^  these are the "working" quotes (one pair for each string)

Steven Parker thank you for your explanation on this. I was getting hun up on doing it all in the method or adding the separators to the literal in console.writeline()