The delimiter (backtick)

A raw string literal is defined as follows:

RawStringDelimeter {RawStringCharacters} RawStringDelimeter 

A backtick is used as the delimiter for raw string literals. I believe that using ` for raw string literals is a good decision. The ` backtick looks like ' (a single quote) and " (a double quote), which have been used as delimiters for character and string literals. The ` backtick will help Java programmers to easily see it as a delimiter for raw strings.

A raw string literal uses ` as a delimiter. A traditional string literal uses " as a delimiter and a character uses ' as a delimiter.

If you wish to include one backtick as a part of the string value, you can use two backticks (``) to define your value. This works for n number of backticks; just make sure to match the count of opening and closing backticks. This sounds interesting. Let's look at an example that includes ` as part of its value:

String html =  
``<HTML>                                      
    <BODY> 
        <H1>I think I like ` as a delimiter!</H1>  
    </BODY> 
</HTML> 
``; 

The following is another example, which uses multiple backticks in the string value and as delimiters. Of course, the count of backticks included in the string value is not equal to the count of backticks used as delimiters:

String html =  
````<HTML>                                      
    <BODY> 
        <H1>I believe I would have liked ``` too(!)</H1>  
    </BODY> 
</HTML> 
````; 
If there is a mismatch between the count of backticks in the opening and closing delimiters, the code won't compile.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.164.141