Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 2.28 KB

how-to-convert-a-string-to-an-array-of-characters.md

File metadata and controls

35 lines (26 loc) · 2.28 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: How to: Convert a String to an Array of Characters in Visual Basic
How to: Convert a String to an Array of Characters
07/20/2015
character arrays [Visual Basic], converting strings
arrays [Visual Basic], converting strings to
examples [Visual Basic], string conversion
strings [Visual Basic], converting to arrays
string conversion [Visual Basic], arrays
1b54b686-ab29-413b-adce-6bd5422376eb

How to: Convert a String to an Array of Characters in Visual Basic

Sometimes it is useful to have data about the characters in your string and the positions of those characters within your string, such as when you are parsing a string. This example shows how you can get an array of the characters in a string by calling the string's xref:System.String.ToCharArray%2A method.

Example 1

This example demonstrates how to split a string into a Char array, and how to split a string into a String array of its Unicode text characters. The reason for this distinction is that Unicode text characters can be composed of two or more Char characters (such as a surrogate pair or a combining character sequence). For more information, see xref:System.Globalization.TextElementEnumerator and The Unicode Standard.

[!code-vbVbVbalrStrings#75]

Example 2

It is more difficult to split a string into its Unicode text characters, but this is necessary if you need information about the visual representation of a string. This example uses the xref:System.Globalization.StringInfo.SubstringByTextElements%2A method to get information about the Unicode text characters that make up a string.

[!code-vbVbVbalrStrings#76]

See also