【问题标题】:Search string to add line after specific word in VB.net搜索字符串以在 VB.net 中的特定单词后添加行
【发布时间】:2013-03-08 10:30:33
【问题描述】:

(我是一个非常基础的程序员)

我有一段文本需要搜索以找到特定单词“客户”,然后将下一行保存为 CustomerName(CustomerName = >line of text

【问题讨论】:

  • 您可以显示示例文本和所需的结果。你有什么尝试过的吗?

标签: vb.net string search save


【解决方案1】:

如果您的“正文”是TextBox,您可以从.Lines 属性中获利:

Dim index As Integer
Dim customerName As String = ""

For i As Integer = 1 to TextBox1.Lines.Length - 1
    If TextBox1.Lines(i-1).Contains("Customer") Then
        customerName =  TextBox1.Lines(i)
        Exit For
    End If
Next

如果你有纯文本,你可以获得分割整个文本的行:

Dim lines() As String = sAllText.Split(Environment.NewLine())

然后像以前一样做,但不是使用TextBox1.Lines,而是使用lines

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2018-07-17
    • 2019-01-25
    • 2014-04-01
    相关资源
    最近更新 更多