Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27388

VS 2008 String reduce

$
0
0
Hi all ,Im trying to reduce string repetitions. Keeping same order to not alterate text. So exemple :

Code:

aabbbbbcccaaaa
Would be :

Code:

a2b5c3a3
I've been trying to figure out ;
Code:

    Dim a As String = vbNull
        Dim b As String = vbNull
        Dim c As String = vbNull
        Dim tmpletter As String = vbNull
        Dim cnt As Integer = 0
        For Each i As String In RichTextBox1.Text
            Dim tmpindex As String = RichTextBox1.Text.IndexOf(i)
            Dim tmpindex2 As String = RichTextBox1.Text.IndexOf(i)
            a = i
            tmpindex += 1
            tmpindex2 += 2
            b = RichTextBox1.Text.Chars(tmpindex)
            c = RichTextBox1.Text.Chars(tmpindex2)
            If a = b Then
                If b = c Then
                    If tmpletter = b Then
                        cnt += 1
                    Else
                        RichTextBox2.Text &= b & cnt
                        tmpletter = b
                    End If
                End If
            End If
        Next

But there i noticed that doesn't work on first strings and doesn't count all. If someone could lead me right , Id appreciate ! Thanks :afrog:

Viewing all articles
Browse latest Browse all 27388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>