2017-05-24 14 views
1

vb.netではどのように文字列から2つの既知の文字の間に発生する文字を削除しますか?ハッシュタグVB.NETは文字列内の2つの文字間の特定の文字を削除します

バランス、#163,464.24#、出納帳閉会バランス:、#86,689.45#、マネー、エンド

+0

文字を列挙するには、「hashtag」にフラグを使用し、フラグが「true」の場合はカンマを削除します。 '# 'の次の出現時にフラグを' false'にセットします。 – Xaqron

答えて

3

あなたはこの単純かつ効率的なアプローチを使用することができますループを使用して、StringBuilder

Dim text = "Balance,#163,464.24#,Cashbook Closing Balance:,#86,689.45#,Money,End" 
Dim textBuilder As New StringBuilder() 
Dim inHashTag As Boolean = False 

For Each c As Char In text 
    If c = "#"c Then inHashTag = Not inHashTag ' reverse Boolean 
    If Not inHashTag OrElse c <> ","c Then 
     textBuilder.Append(c) ' append if we aren't in hashtags or the char is not a comma 
    End If 
Next 
text = textBuilder.ToString() 
+1

これは間違いなく私よりもはるかに安全な提案です。 –

+0

@tim schmelterは完璧に働いてくれてありがとう、ありがとう@A Friend – Muroiwa263

-1

私は正規表現が下手だから:

Dim str = "Balance,#163,464.24#,Cashbook Closing Balance:,#86,689.45#,Money,End" 
Dim split = str.Split("#"c) 
If UBound(split) > 1 Then 
    For i = 1 To UBound(split) Step 2 
     split(i) = split(i).Replace(",", "") 
    Next 
End If 
str = String.Join("#", split) 
関連する問題