2015-07-21 63 views
0

我想解決登錄到vb解決方案的特定人員。基本上這些人有一個登錄號,可以說1111111。我試圖說,如果第5位是9,那麼1111911然後給他們一個消息,不要讓他們繼續進行。VB給定的數字排序

我有一個現在說IF IF givenNumber.StartsWith ("")然後 我想要類似的東西。

回答

0

你的例子表明givenNumber是一個字符串。您可以將String視爲Char的數組。

If givenNumber(4) = "9"c Then 
    '5th digit is "9" 
End If 
1

也可以用做String.Substring()

從此實例檢索子。子字符串起始於 指定的字符位置並具有指定的長度。

簡單的例子:

If strLoginID.Substring(4, 1) = "9" Then 
    MessageBox.Show("Please enjoy this public service announcement concerning unicorns.") 
End If 

您可能還需要檢查字符串有至少5個字符,以避免運行時異常:

If strLoginID.Length >=5 Then 
    If strLoginID.Substring(4, 1) = "9" Then 
     MessageBox.Show("Please enjoy this public service announcement concerning unicorns.") 
    End If 
Else 
    MessageBox.Show("ID not long enough; you are not worthy to be in the presence of unicorns.") 
End If