Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Looking for a better answer again

$
0
0
Hello folks, I've got a problem here where I need to take a number stored as a string and split the digits when the string length is two (i.e 10 becomes 1 0) or if the length is one, I need to add a tab and a 0 to the number (i.e. 1 also becomes 1 0). I wrote a quick and dirty program to accomplish this, but my GOD is it slow. Surely there's a faster way to process simple text than this:

    Private Sub txtInput_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInput.DoubleClick
        txtInput.Text = Clipboard.GetText
        For i = 0 To txtInput.Lines.Count - 1
            If Len(txtInput.Lines(i)) = 1 Then 
                txtOutput.Text = txtOutput.Text & txtInput.Lines(i).Substring(0, 1) & vbTab & "0" & vbNewLine
            ElseIf Len(txtInput.Lines(i)) = 2 Then
                txtOutput.Text = txtOutput.Text & txtInput.Lines(i).Substring(0, 1) & vbTab & txtInput.Lines(i).Substring(1, 1) & vbNewLine
            Else
                'Do nothing (don't want to output blank lines or lines longer than 2)
            End If
            Me.Text = "Processing Line: " & i
        Next
        txtInput.SelectAll()
        Clipboard.SetText(txtOutput.Text)
    End Sub


Viewing all articles
Browse latest Browse all 51036

Trending Articles



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