| 1 | = Escape Sequences = |
---|
| 2 | |
---|
| 3 | ''Part of'' TutorialIntermediate |
---|
| 4 | |
---|
| 5 | == Description == |
---|
| 6 | |
---|
| 7 | Escape sequence are useful, but they can get tricky. |
---|
| 8 | |
---|
| 9 | Demonstrates how to use escaping to put backslashes and apostrophes |
---|
| 10 | for a literal character. |
---|
| 11 | |
---|
| 12 | == Example == |
---|
| 13 | |
---|
| 14 | {{{ |
---|
| 15 | #!d |
---|
| 16 | import std.stdio; |
---|
| 17 | |
---|
| 18 | const string backslashWYSIWYG = `\`; |
---|
| 19 | const string quoteWYSIWYG = `'`; |
---|
| 20 | const string doubleQuoteWYSIWYG = `"`; |
---|
| 21 | |
---|
| 22 | const string doubleQuoteReg = "\""; |
---|
| 23 | const string quoteReg = "\'"; |
---|
| 24 | const string backslashReg = "\\"; |
---|
| 25 | |
---|
| 26 | const char quoteChar = '\''; |
---|
| 27 | const char backslashChar = '\\'; |
---|
| 28 | |
---|
| 29 | const string rawString = r"\\\"; |
---|
| 30 | |
---|
| 31 | void main() |
---|
| 32 | { |
---|
| 33 | writeln(doubleQuoteReg ~ "That's what I said!" ~ doubleQuoteReg); |
---|
| 34 | writeln("raw string: ", rawString); |
---|
| 35 | } |
---|
| 36 | }}} |
---|
| 37 | |
---|
| 38 | Note that you can use the '''r"''literalstring''"''' form to stop treating backlash as an escape sequence character. |
---|
| 39 | |
---|
| 40 | == Partial Source == |
---|
| 41 | |
---|
| 42 | || Link || http://jcc_7.tripod.com/d/tutor/escape.html || |
---|
| 43 | || Author || jcc7 || |
---|
| 44 | |