How to: Use Escape Sequences in Text Templates

Text template files support the use of the escape character "\" to enable things such as quoted strings. You can also use escape sequences to generate text template tags to output files or to create text templates from text templates. For more information, see How to: Generate Templates from Templates By Using Escape Sequences.

Note

Visual Basic does not support escape sequences to enable quoted strings.

You can use the following escape characters to retain text template tags in the output file.

\<# … \#>

If you require a text block that includes strings used to delimit other text template blocks, then you may use the following escape sequences:

  • If an even number of escape (\) characters precede either the text block tag or the other block tag, half of the "\" characters will be generated in the post-parsing code, and the tag is considered to be a start/end tag. For example, if there are four escape characters in the text template, there will be two "\" characters in the generated file

  • If an odd number of escape (\) characters precede either the text block tag or the other block tag, half of the "\" characters plus the tag itself (<# or #>) will be generated in the post-parsing code. The tag is not considered to be a start/end tag.

  • If an escape (\) character appears anywhere else in any sequence other than where it escapes a double quote (") in a directive block, the escape receives no special treatment. For example, "\a", "\<\#", and "#\>" will be ignored by the parser. The "\" will be left as it is in the post-parsing code.

To use escaping in a text template

  • Use the escape character "\" as required. For example, to retain the quoted string name, you can use the following syntax.

    <# string name = "\"QuotedStringName\""; #>
    <#= name #>
    

See Also

Concepts

Text Syntax (Domain-Specific Languages)

Reference

Character Escapes

Other Resources

Generating Specific Kinds of Artifacts from Text Templates

Adding Code to Text Templates

Generating Artifacts By Using Text Templates

Change History

Date

History

Reason

July 2008

Rewrote and refactored project.

Content bug fix.