2015-07-20 75 views

回答

2

使用中間值。

Change all 0 -> 2 
Change all 1 -> 0 
Change all 2 -> 1 
0

另一種選擇是將字符串轉換爲字符數組,逐個迭代每個字符;然後建立從修改後的數組一個新的字符串(或覆蓋原):

Dim data As String = "00110010101101001010" 
    Dim arr() As Char = data.ToCharArray 
    For i As Integer = 0 To arr.Length - 1 
     arr(i) = If(arr(i) = "1", "0", "1") 
    Next 
    Dim data2 As New String(arr) 
    Debug.Print(data) 
    Debug.Print(data2) 
1

如何:

Dim text = "00110010101101001010" 
    Dim flipped = New String(text.Select(Function(c) If(c = "0"c, "1"c, "0"c)).ToArray()) 

這給了我:

11001101010010110101 
相關問題