Function
を使用できます。
Public Function ReadInBetweenSameDepth(str As String, delimiterStart As Char, delimiterEnd As Char) As String
If delimiterStart = delimiterEnd OrElse String.IsNullOrWhiteSpace(str) OrElse str.Length <= 2 Then
Return Nothing
End If
Dim delimiterStartFound As Integer = 0
Dim delimiterEndFound As Integer = 0
Dim posStart As Integer = -1
For i As Integer = 0 To str.Length - 1
If str(i) = delimiterStart Then
If i >= str.Length - 2 Then
'delimiter start is found in any of the last two characters
Return Nothing
End If
'it means, there isn't anything in between the two
If delimiterStartFound = 0 Then
'first time
posStart = i + 1
End If
'assign the starting position only the first time...
'increase the number of delimiter start count to get the same depth
delimiterStartFound += 1
End If
If str(i) = delimiterEnd Then
delimiterEndFound += 1
If delimiterStartFound = delimiterEndFound AndAlso i - posStart > 0 Then
Return str.Substring(posStart, i - posStart)
'only successful if both delimiters are found in the same depth
End If
End If
Next
Return Nothing
End Function
(例えば(
と)
など)区切り文字が同じ「深さ」である場合、それは基本的にチェックします。
出典
2016-05-18 03:52:48
Ian
私はちょうどRegExを使用してPHPでstackoverflowの人の助けを借りてそれをしたので、私はそれをやろうとしましたが、あなたのアイデアを放棄し、良い機能! –
@ MasterDJonああ、ありがとう...私は光栄です。 – Ian
ヘルプheheありがとう –