How to use in a string that contains double quotes in its contents along with the @marker

Asked

Viewed 33 times

-1

I am creating a simple unit test that compares two strings and would like to use the marker @ to leave the contents of a string formatted in several lines as follows:

   var esperado =  @"123|teste|teste|\"GET / algunNomeDeRquivo.txt HTTP / 1.1\"|100.2
    453| 404| MISS | \"POST /myImages HTTP/1.1\" | 999
    199 | 404 | MISS | \"GET /testte HTTP/1.1" | 999
    312 | 201| TESTE| "GET /teste.txt HTTP/1.1\" | 999";

But when I add the marker @ it recognizes the quotes inside the string as the end marker of the string. Is there any way to keep the @ in strings that have double quotes in their contents?

  • 2

    only put two "" ... @"123|teste|teste|""GET..."

  • You can also use Stringbuilder, to separate by lines to organize, for example: Stringbuilder expected = new Stringbuilder(); expected.Append("123|test|"GET / someName.HTTP file.txt / 1.1" |100.2");

1 answer

0

Hello,

Use two double quotes in the body of the string, for example:

var esperado = @"123|teste|teste|""GET / algunNomeDeRquivo.txt HTTP / 1.1\""|100.2
                453 | 404 | MISS | \""POST /myImages HTTP/1.1\"" | 999
                199 | 404 | MISS | \""GET /testte HTTP/1.1"" | 999
                312 | 201 | TESTE | ""GET /teste.txt HTTP/1.1\"" | 999";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.