如何使用set参数逐行读取richtextbox行到另一个richtextbox [英] How to read richtextbox lines by line to another richtextbox only with set parameter
问题描述
Hello Experts,
我有一个包含100行的Richtextbox1。它与alphanumberic行混合。
i只想要满足以下参数的行。
前3个字母是数字
第4个字母应该短划线 -
从5到12个字母是数字的
从13到18个字母是字母表
19字母是正斜杠/
示例行 - 789-12123434LHRMUC /
i只需要行到符合上述参数的Richtexbox2。
请帮助对此进行排序。
我的尝试:
Hello Experts,
i have a Richtextbox1 with 100 lines. it is mixed with alphanumberic lines.
i only wanted lines which is meeting following parameters.
1st 3 letters are Numeric
4th letter should be dash "-"
from 5th to 12 letters are numeric
from 13th to 18 letter are alphabet
19th letter is forward slash "/"
example lines - 789-12123434LHRMUC/
i only need lines to Richtexbox2 which meet above parameters.
kindly help to sort this.
What I have tried:
For Each line In RichTextBox1.Lines
richtextbox2.line (1)= (RichTextBox1.Lines(1))
Next
推荐答案
您可以使用正则表达式 [ ^ ]:
You can use Regex[^]:
Dim lines As String()= New String(){"789-12123434LHRMUC/",
"78Z-1R123434LHRMUC/", "A89-12123434LHRM1C/", "989-12853434LHRMOU/",
"789-12123434LHRMUC/T1K71MC1.06/CONSOLIDATION/PILCRT"}
Dim pattern As String = "^\d{3}-\d{8}\w{6}/"
Dim r As Regex = New Regex(pattern)
Dim result = lines.Where(Function(x) r.Match(x).Success) _
.Select(Function(x) New With { _
.line = x, _
.match = r.Match(x).Value, _
.remaining = x.Replace(r.Match(x).Value,"")}) _
.ToArray()
string[] lines = new string[]{"789-12123434LHRMUC/",
"78Z-1R123434LHRMUC/", "A89-12123434LHRM1C/", "989-12853434LHRMOU/",
"789-12123434LHRMUC/T1K71MC1.06/CONSOLIDATION/PILCRT"};
string pattern = @"^\d{3}-\d{8}\w{6}/";
Regex r = new Regex(pattern);
var result = lines.Where(x=>r.Match(x).Success)
.Select(x=>new{
line = x,
match = r.Match(x).Value,
remaining = x.Replace(r.Match(x).Value,"")})
.ToArray();
详情请见:正则表达式语言 - 快速参考| Microsoft Docs [ ^ ]
这篇关于如何使用set参数逐行读取richtextbox行到另一个richtextbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!