StringReader读取文本框中的下一个字符串以标记 [英] StringReader read next string in textbox to label

查看:94
本文介绍了StringReader读取文本框中的下一个字符串以标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图找出为什么我只使用字符串阅读器将第一个字符串返回到我的标签但之后没有任何内容。



我正常使用表达式从richtextbox内的字符串中抓取新添加的数据到标签以进行测试但由于某种原因它只抓取第一个匹配并在标签中显示它,但之后的任何其他匹配都不会将标签更改为下一个匹配。我认为它只读取第一场比赛,因为条件已经满足或只是读取第一个字符串?





I have been trying to figure out why I only get the first string returned to my label using string reader but then nothing after that.

I am using regular expressions to grab newly added data from a string inside a richtextbox to a label for testing purposes but for some reason it only grabs the first match and displays it in the label but any other match after that it does not change the label to the next match. I think it only reads the first match because the condition has been met or it is only reading the first string?


Dim Data4 As New Regex("\b\w{4}\b", RegexOptions.IgnoreCase)
Dim reader As New StringReader(RichTextBox2.Text)
Dim tmp As String = reader.ReadToEnd
Dim MD0 As Match = Data4.Match(tmp)
For Each M As String In RichTextBox2.Lines
           If M.Contains(MD.ToString) Then
               Label4.Text = MD0.ToString
           End If
       Next M







Im新手使用字符串阅读器

不确定进出口




Im new to using string reader
not sure of the ins and outs yet

推荐答案

好的经过一些测试后看来它正在寻找什么是包含4个字符的单词。



这是一个小样本,它使用上面的链接作为指南并使用富文本框输入来重写大部分使用的代码这里输出的标准texbox就是我最终得到的结果。



输入就是这个。

这对于mannnnnny leters来说是个蠢货tttt AbCd



输出就是这个。

这个

tttt

Abbd





Ok after some testing it appears that what it is looking for is words containing 4 Chars.

Here is a small sample that rewrites most of the code used, using the above link as a guide and using a rich text box for input and a standard texbox for output here is what I ended up with.

Input is this.
this is a tesssssst for to mannnnnnny leters tttt AbCd

Output is this.
this
tttt
AbCd


Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
    Try
        Dim strbldr As New StringBuilder
        Dim regtext As String
        If tbInput.Text = Nothing Then
            MsgBox("Nothing was entered")
            Exit Sub
        Else
            regtext = tbInput.Text
        End If

        Dim pattern As String = ("\b\w{4}\b")
        Dim rgx As New Regex(pattern)
        For Each M As Match In rgx.Matches(regtext)
            strbldr.AppendLine(M.ToString)
        Next M

        tbOutput.Text = strbldr.ToString
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub


首先,您阅读了所有文字。由于一些奇怪的原因,你只是看不到它。



问题是:根本没有意义。你看,

First of all, you do read all text. By some weird reason, you just cannot see it.

The problem is: it makes no sense at all. You see,
Dim reader As New StringReader(RichTextBox2.Text)
Dim tmp As String = reader.ReadToEnd

相当于

is equivalent to

Dim tmp As String = RichTextBox2.Text

那么,为什么要使用 StringReader 呢?只是不要这样做。



-SA

So, why using StringReader at all? Just don't do it.

—SA


这篇关于StringReader读取文本框中的下一个字符串以标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆