VB.NET tutorial-String Manipulation: Concat Chars and ToCharArray

String Manipulation



Concat Chars and ToCharArray


Concat function
The Concat function is used to combine strings.
st=String.Concat(str1,str2,…)
Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello")
        Dim str2 As New String(" ")
        Dim str3 As New String("World")
        Dim st As String
        st = String.Concat(str1, str2, str3) 'combine 3 strings
        Console.WriteLine(st)
        Console.ReadLine()
    End Sub
 
End Module
 


Chars function
The Chars function returns a character of a specified index in a string.
c=Str.Chars(index)
Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        Dim c As Char
        c = str1.Chars(0)’return the first character in str1
        Console.WriteLine(c)
        Console.ReadLine()
    End Sub
 
End Module
 


ToCharArray function
The ToCharArray function return an array of characters from a string.
carray=Str.ToCharArray
 
Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        Dim c() As Char
        Dim i As Integer
        c = str1.ToCharArray 'Convert str1 to an array of characters
        For i = 0 To c.Length - 1
            Console.WriteLine(c(i))
        Next
 
 
        Console.ReadLine()
    End Sub
 
End Module





Comments

Name:
Comment:
Enter the text:
CAPTCHA image

....................................................................................................................Home | Forum | About | Contact
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.
Copyright @ 2011-2013 worldbestlearningcenter. All Rights Reserved.
Home Programming Web DB & App Questions Exercises Tips Programs FAQs Download About
Computer-Wbest
Popular Pages
You might like