Member-only story
Hi everyone, welcome back. In these examples, we will be going over how to add quotation marks into string variables in C#. A string variable is used to hold a collection of characters, which can be used to save text. We will be going over how to add in single quotes and double quotes in with our strings. With this introduction out of the way, let’s get into it.
Creating a String with Single Quotes
Let’s start by seeing how we can create a string that contains single quotes. We can do this by using a backslash followed by a single quote to tell C# that we want to add a single quote into our string. Let’s see an example:
string myString = "Hey, that\'s my car!";
Console.WriteLine(myString);Output:
Hey, that's my car!
In the example above, we can see that we have successfully added a single quote within our text by using the backslash followed by a single quote. We can verify the text by printing and checking the output.
Creating a String with Double Quotes
Now, let’s see how we can create a string that contains double quotes. We can do this by using a backslash followed by a double quote to tell C# that we want to add a single quote into our string…