2016-10-01 2 views
-1

私はこれまでにこのような質問を投稿しましたが、回答があってもコードはそれ以上に速くできませんでした。私はコードをそれまでのものに変更し、コードをスピードアップする方法のアドバイスを探しています。VB.netループでは8秒かかりますが、遅いと感じます。

私は30k行のリッチテキストボックスを持っており、各ループが30k行を含むrichtextboxの特定の行に到達すると、テキストブロックを置き換える必要があります。 (変数は、このコードで宣言されていない場合、彼らはグローバル変数であることを意味)

ここでは私のコードです:ここでは

Dim counter As Integer = 0 
     Dim startcount As Boolean = False 
     Dim holdstring As String = "" 


     Dim completertb4 As New StringBuilder("") 
     Dim completertb4one As New StringBuilder("") 
     MsgBox(newrtb.Lines.Count,, "") 
     Dim counteroflines As Integer = 1 
     For Each line As String In newrtb.Lines 

      'MsgBox(counteroflines & "----" & holdstring,, "") 

      If line.Contains(richtextboxl0) Then 
       startcount = True 
       holdstring = vbNewLine & richtextbox3text 

      ElseIf startcount = True Then 
       If counter = temptextbox3count Then 
        startcount = False 
       Else 
        counter += 1 
       End If 

      ElseIf completertb4.ToString = "" Then 
       holdstring = line 
      Else 
       holdstring = line 

      End If 

      If counteroflines >= 1 And counteroflines <= 10000 Then 

       completertb4.Append(vbNewLine & holdstring & "----" & counteroflines) 
      Else 

       completertb4one.Append(vbNewLine & holdstring & "----" & counteroflines) 
      End If 

      counteroflines += 1 
     Next 
+0

サンプルデータを説明したり提供したりできますか? –

+0

私は問題を解決しました、ありがとう! –

答えて

0

は、私は0:01秒に8時00秒から私のコードを縮小する方法です。 8秒から1秒未満。

  Dim counter As Integer = 0 
     Dim countertrue As Integer = 0 
     Dim countintertal As Integer = 0 


     Dim newrtbstrarray As String() = newrtb.Lines 
     Dim rtb3array As String() = richtextbox3text.Lines 

     For Each line As String In newrtbstrarray 

      If line.Contains(richtextboxl0) Then 
       countertrue = counter 
       For Each element As String In rtb3array 
        newrtbstrarray(countertrue) = rtb3array(countintertal) 
        countertrue += 1 
        countintertal += 1 
       Next 

      End If 

      counter += 1 
     Next 
関連する問題