TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET ToCharArray Function

Use the ToCharArray Function, which converts a String to a Char array.
ToCharArray converts a String to a Char array. It returns a Char array with a number of elements equal to the Length of the String. With this Char array, we change the String data efficiently, without again copying it.StringsArray
Example. First, this program declares and assigns a string that points to the literal "Perls". Then, the ToCharArray function is called on the String variable. Finally, the For-Each loop enumerates all the characters in the array.

Note: You can see that the character array contains the same five characters as the original string.

For Each, For
VB.NET program that uses ToCharArray function Module Module1 Sub Main() ' String input value. Dim value As String = "Perls" ' Call ToCharArray function. Dim array() As Char = value.ToCharArray ' Loop over Char array. For Each element As Char In array Console.WriteLine(element) Next End Sub End Module Output P e r l s
Discussion. A main reason you will want to use Char arrays based on your Strings in your VB.NET programs is that Char arrays are mutable and String instances are not. This can improve performance.

Note: You can change the individual characters in a Char array without copying the entire set of characters again.

Char Array
Summary. ToCharArray converts strings to their equivalent Char arrays. This enables you to change characters without having to copy strings. You cannot cast the String to a Char array. You must convert it—the best way is usually with ToCharArray.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf