Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve Unicode escape sequence info (C#) #13162

Merged
merged 1 commit into from Jul 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/csharp/programming-guide/strings/index.md
@@ -1,7 +1,7 @@
---
title: "Strings - C# Programming Guide"
ms.custom: seodec18
ms.date: 07/20/2015
ms.date: 06/27/2019
helpviewer_keywords:
- "C# language, strings"
- "strings [C#]"
Expand Down Expand Up @@ -56,13 +56,16 @@ A string is an object of type <xref:System.String> whose value is text. Internal
|\n|New line|0x000A|
|\r|Carriage return|0x000D|
|\t|Horizontal tab|0x0009|
|\U|Unicode escape sequence for surrogate pairs.|\Unnnnnnnn|
|\u|Unicode escape sequence|\u0041 = "A"|
|\U|Unicode escape sequence (UTF-32)|`\U00nnnnnn` (e.g. `\U0001F47D` = "&#x1F47D;")|
|\u|Unicode escape sequence (UTF-16)|`\unnnn` (e.g. `\u0041` = "A")|
|\v|Vertical tab|0x000B|
|\x|Unicode escape sequence similar to "\u" except with variable length.|\x0041 or \x41 = "A"|
|\x|Unicode escape sequence similar to "\u" except with variable length.|`\x0041` or `\x41` = "A"|

> [!WARNING]
> When using the `\x` escape sequence and specifying less than 4 hex digits, if the characters that immediately follow the escape sequence are valid hex digits (i.e. 0-9, A-F, and a-f), they will be interpreted as being part of the escape sequence. For example, `\xA1` produces "&#161;", which is code point U+00A1. However, if the next character is "A" or "a", then the escape sequence will instead be interpreted as being `\xA1A` and produce "&#x0A1A;", which is code point U+0A1A. In such cases, specifying all 4 hex digits (e.g. `\x00A1` ) will prevent any possible misinterpretation.

> [!NOTE]
> At compile time, verbatim strings are converted to ordinary strings with all the same escape sequences. Therefore, if you view a verbatim string in the debugger watch window, you will see the escape characters that were added by the compiler, not the verbatim version from your source code. For example, the verbatim string @"C:\files.txt" will appear in the watch window as "C:\\\files.txt".
> At compile time, verbatim strings are converted to ordinary strings with all the same escape sequences. Therefore, if you view a verbatim string in the debugger watch window, you will see the escape characters that were added by the compiler, not the verbatim version from your source code. For example, the verbatim string `@"C:\files.txt"` will appear in the watch window as "C:\\\files.txt".

## Format Strings
A format string is a string whose contents are determined dynamically at runtime. Format strings are created by embedding *interpolated expressions* or placeholders inside of braces within a string. Everything inside the braces (`{...}`) will be resolved to a value and output as a formatted string at runtime. There are two methods to create format strings: string interpolation and composite formatting.
Expand Down