Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 2.42 KB

how-to-write-characters-to-a-string.md

File metadata and controls

45 lines (36 loc) · 2.42 KB
description title ms.date dev_langs helpviewer_keywords ms.assetid
Learn more about: How to: Write characters to a string
How to: Write characters to a string
01/21/2019
csharp
vb
data streams, writing characters to string
writing characters to strings
streams, writing characters to strings
I/O [.NET], writing characters to strings
1222cbeb-0760-44bf-9888-914a2a37174b

How to: Write characters to a string

The following code examples write characters synchronously or asynchronously from a character array into a string.

Example: Write characters synchronously in a console app

The following example uses a xref:System.IO.StringWriter to write five characters synchronously to a xref:System.Text.StringBuilder object.

[!code-csharpConceptual.StringBuilder#9] [!code-vbConceptual.StringBuilder#9]

Example: Write characters asynchronously in a WPF app

The next example is the code behind a WPF app. On window load, the example asynchronously reads all characters from a xref:System.Windows.Controls.TextBox control and stores them in an array. It then asynchronously writes each letter or white-space character to a separate line of a xref:System.Windows.Controls.TextBlock control.

[!code-csharpStreamReaderWriter] [!code-vbStreamReaderWriter]

See also