VB可透過迴圈挨個檢測字元A或a在輸入字串中出現的頻次。1)使用Mid函式。Mid 函式,返回 Variant (String),其中包含字串中指定數量的字元。2)For Next迴圈。For...Next 語句,以指定次數來重複執行一組語句。3)Len 函式,返回 Long,其中包含字串內字元的數目,或是儲存一變數所需的位元組數。Private Sub Command1_Click() Dim strSj As String Dim i As Long Dim j As Long strSj = InputBox("輸入字串", strSj) Text1 = strSj For i = 1 To Len(strSj) If Mid(strSj, i, 1) = "A" Or Mid(strSj, i, 1) = "a" Then j = j + 1 End If Next Text2 = jEnd Sub
VB可透過迴圈挨個檢測字元A或a在輸入字串中出現的頻次。1)使用Mid函式。Mid 函式,返回 Variant (String),其中包含字串中指定數量的字元。2)For Next迴圈。For...Next 語句,以指定次數來重複執行一組語句。3)Len 函式,返回 Long,其中包含字串內字元的數目,或是儲存一變數所需的位元組數。Private Sub Command1_Click() Dim strSj As String Dim i As Long Dim j As Long strSj = InputBox("輸入字串", strSj) Text1 = strSj For i = 1 To Len(strSj) If Mid(strSj, i, 1) = "A" Or Mid(strSj, i, 1) = "a" Then j = j + 1 End If Next Text2 = jEnd Sub