【发布时间】:2018-11-12 13:03:56
【问题描述】:
您好,我尝试查找代表数字的特定单词
例如:
- RichTextBox 中的数字“一”
我的代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = RichTextBox1.Text
Dim strarr() As String
strarr = str.Split(" "c)
For Each s As String In strarr
Dim words() As String = s.ToLower.Split({" "c}, StringSplitOptions.RemoveEmptyEntries)
If words.Count(Function(w) RichTextBox2.Text.Contains(w)) > 0 Then
Label1.Text = s
Label1.Text = "Founded"
Else
Label1.Text = "not founded, if we find it, we will type it , in label1"
End If
Next
End Sub
RichTextBox2 = 我的单词列表 (1 - 5) 个数字。
RichTextBox1 = 我专注于它。
问题是当我输入 RichTextBox1.texthello i want type numbers, on
它会将“on”检测为(一)。这不是我的目的。
【问题讨论】:
-
我想有点儿得到你想要的,但只是为了确定:你想写在一个盒子里,点击一个按钮,然后在第一个盒子里找到的所有数字都被重新写在第二个盒子?
-
不要使用
Contain(),使用Equals(),也许添加StringComparison.CurrentCultureIgnoreCase。Regex.Matches可能会更好,如果您还想知道有多少 找到 符合条件的单词 以及它们在文本中的位置。 -
首先,直接输出。它永远不会显示找到的内容(
string s中的内容),因为它会被文本Founded覆盖。你会看到它会输出一些与你想象的不同的东西。
标签: .net regex vb.net visual-studio-2012