用另一个字符串替换多行文本框的特定行

时间:2015-03-19 20:44:36

标签: vb.net winforms

我正在尝试用其他字符串替换多行文本框中的一行。首先,我正在搜索文本框,如果找到匹配项,那么我试图替换整行。但是,到目前为止我的测试失败了。有什么想法吗?

 If txtImageMap.Text.IndexOf(sSelectedControl, 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
            ' Found
            For i = 0 To txtImageMap.Lines.Length - 1
                If txtImageMap.Lines(i).StartsWith(sSelectedControl) Then
                    txtImageMap.Lines(i) = txtImageMap.Lines(i).Replace(txtImageMap.Lines(i), sEntry)
                End If
            Next
            txtImageMap.Refresh()
 End If

1 个答案:

答案 0 :(得分:1)

我对VB.Net并不熟悉,但这可能有所帮助:

Dim tempArray() as String
tempArray = txtImageMap.Lines

For i = 0 To tempArray.Length - 1
   If tempArray(i).StartsWith(sSelectedControl) Then
       tempArray(i) = tempArray(i).Replace(tempArray(i), sEntry)
   End If
Next

txtImageMap.Lines = tempArray

我在C#中做过同样的事情。 (我猜它是相同的。行数组是一个只读数组,所以你必须通过tempArray去)

相关问题