String escape double quote
The following console c# example code demonstrate us how can we escape double quote in a string programmatically at run time in an console application. .Net framework’s String Class represent text as a series of Unicode characters. We can escape double quotes (“) in a string by several ways.
We can escape double quotes in a string by using a escape character Backslash (\). If we want to include a double quotes in this way, we should write the string as (“a \”sample\” text”). Here the word (sample) will be surrounded by two double quotes as “sample”.
We also can escape double quotes in a string object by using @ symbol. If we want to write the same string in this technique, then we should format it as (@”a “”sample”” text”). Here we also need to place a double quotes two times to get output a single double quotes. Both techniques show the same output.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Program { static void Main(string[] args) { //this section create string variable with double quote. string stringPlants = "\"Brown Betty\" \"Meadow Cabbage\" \"Swamp Cabbage\""; //another way to escape double quote in string string stringPlants2 = @"""California Sycamore"" ""California Walnut"" ""Canada Root"""; Console.WriteLine("string of plants.................."); Console.WriteLine(stringPlants); Console.WriteLine(stringPlants2); Console.ReadLine(); } } |
Output:
1 2 3 4 5 | string of plants.................. "Brown Betty" "Meadow Cabbage" "Swamp Cabbage" "California Sycamore" "California Walnut" "Canada Root" |