說我有以下字符串:含vb.net驗證字符串backslahes
C:\folder1\folder2\ <- this is valid
C:\foler1\folder2 <- this is invalid
C:\folder1\folder2\folder3 <- invalid
基本上我想檢查用戶進入目錄的格式爲
C:\somthing\somthing\
別的無效
最佳方法?正則表達式?或字符串函數?
當前VB方法:
Private Sub txtboxLocRoot_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtboxLocRoot.Validating
If txtboxLocRoot.Text.Split("\").Length - 1 <> 3 Then
MsgBox("Local root must be in the format 'C:\dir1\[folder name]\'", vbExclamation, "Error")
Return
End If
Dim foldernamearray() As String = Split(txtboxLocRoot.Text, "\")
pfoldername = foldernamearray(2)
txtboxLocRoot.Text = "C:\dir1\" & pfoldername & "\"
End Sub
有效作爲「是正確的格式字符串」的文件系統上存在不檢查實際的目錄 –
你知道如何用字符串函數和/或正則表達式來完成它,只需要關於哪個選項的建議?或者你需要幫助開始使用字符串函數/正則表達式? – hawbsl
無法讓正則表達式工作,我有vb解決方案,它使用拆分工作。 –