GetChar() 函數用於從指定索引的字符串中獲取字符。
用法:
GetChar(str,index)
參數:
- str:它是一個指定的字符串。
- index: 它是從字符串中獲取字符的索引。
返回值:
Val() 函數將返回指定索引上的字符串中的字符。
程序/源代碼:
下麵給出了演示 GetChar() 函數的源代碼。給定的程序已成功編譯並執行。
'VB.Net program to demonstrate the GetChar() function.
Module Module1
Sub Main()
Dim ch As Char
Dim str1 As String = "Hello World"
Dim str2 As String = "Hello India"
Dim str3 As String = "Hello Delhi"
ch = GetChar(str1, 5)
Console.WriteLine("Char at index {0}:{1}", 5, ch)
ch = GetChar(str2, 7)
Console.WriteLine("Char at index {0}:{1}", 7, ch)
ch = GetChar(str3, 8)
Console.WriteLine("Char at index {0}:{1}", 8, ch)
End Sub
End Module
輸出:
Char at index 5:o Char at index 7:I Char at index 8:e Press any key to continue . . .
說明:
在上麵的程序中,我們創建了一個包含 Main() 方法的模塊 Module1。在 Main() 方法中,我們創建了三個變量 str1、str2 和 str3,分別用 "Hello World"、"Hello India" 和 "Hello Delhi" 初始化。
ch = GetChar(str1, 5) Console.WriteLine("Char at index {0}:{1}", 5, ch) ch = GetChar(str2, 7) Console.WriteLine("Char at index {0}:{1}", 7, ch) ch = GetChar(str3, 8) Console.WriteLine("Char at index {0}:{1}", 8, ch)
在上麵的代碼中,我們從指定索引上的指定字符串中獲取字符,然後將它們打印在控製台屏幕上。
相關用法
- VB.NET LTrim()用法及代碼示例
- VB.NET DateTime FromBinary()用法及代碼示例
- VB.NET CLng()用法及代碼示例
- VB.NET RTrim()用法及代碼示例
- VB.NET Array Reverse()用法及代碼示例
- VB.NET DateTime ToBinary()用法及代碼示例
- VB.NET Array Resize()用法及代碼示例
- VB.NET CInt()用法及代碼示例
- VB.NET CULng()用法及代碼示例
- VB.NET CDbl()用法及代碼示例
- VB.NET LCase()用法及代碼示例
- VB.NET Array ConstrainedCopy()用法及代碼示例
- VB.NET Array Clear()用法及代碼示例
- VB.NET Array LastIndexOf()用法及代碼示例
- VB.NET String Join()用法及代碼示例
- VB.NET String IsNullorWhitSpace()用法及代碼示例
- VB.NET InStr()用法及代碼示例
- VB.NET Array BinarySearch()用法及代碼示例
- VB.NET CByte()用法及代碼示例
- VB.NET CBool()用法及代碼示例
注:本文由純淨天空篩選整理自 VB.Net program to demonstrate the GetChar() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。