2010年3月7日 星期日

字串處理練習

2010-3-7 下午 12-35-01 

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a = "22233577"
        Dim str1 = ""
        Dim p = ""
        Dim n = 1
        For i = 1 To a.Length
            Dim c = Mid(a, i, 1)
            If c <> p Then
                If str1 = "" Then
                    str1 = str1 & c & "^ "
                Else
                    str1 = str1 & n & "*" & c & "^"
                End If
                n = 1
            Else
                n = n + 1
            End If
            p = c
        Next
        str1 = str1 & n
        str1 = Replace(str1, "^1", "")
        MsgBox(str1)
    End Sub
End Class

沒有留言: