How to use string chars (str.Chars() ) in VB.net
By: Issac
The VB.NET String Chars method returns the character at the specified index of an instance
System.String.Chars(ByVal index As Integer) As Char
Parameters:
Integer index – specifies the position of the character in the returned Character.
Returns:
Char - The return Character.
For ex :
"Return test".Chars(3) return a single character 'u'
If u pass a number more than String length will return an exception
"Return test".Chars(25) will throw a System.IndexOutOfRangeException
Exceptions:
System.IndexOutOfRangeException : when the index is less than zero or greater than the length of String Object,this exception is thown
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = "allpctips.com"
Dim singleChar1 As Char
singleChar = str.Chars(3)
MsgBox(singleChar1)
End Sub
End Class
When you run this source code you will return a messagebox show 'p'
Archived Comments
1. CharlesTig
View Tutorial By: CharlesTig at 2017-06-12 22:35:15
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Getting an Exception's Number and Description in VB.net
Raising an Exception Intentionally in VB.net
Exception Filtering in the Catch Block in VB.net
Using Multiple Catch Statements in VB.net
Throwing an Exception in VB.net
Throwing a Custom Exception in VB.net
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net