快速,最好的方式获取单词内容字符串 [英] Fast and best way get content string in words

查看:58
本文介绍了快速,最好的方式获取单词内容字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:



输入:



dim msg as string =Agen 05,Pembelian SM5.08132166171 Hrg = 5500 SUKSES SN:3778882223. Saldo Rp。(Awal 780700 Akhir 775200)



我希望字符串输出:

SN:3778882223



希望你帮忙,



我试过的:



i try



'Dim arr As String()= Regex.Split( msg,\ W +)

'为每个消息在arr

'MessageBox.Show(sPesan)

'Next

i have code like this :

input :

dim msg as string = "Agen 05, Pembelian SM5.08132166171 Hrg=5500 SUKSES SN: 3778882223. Saldo Rp.(Awal 780700 Akhir 775200)"

and i hope string output :
SN: 3778882223

hope you help,

What I have tried:

i try

'Dim arr As String() = Regex.Split(msg, "\W+")
'For Each msg In arr
' MessageBox.Show(sPesan)
'Next

推荐答案

试试这个:

Try this:
Imports System
Imports System.Text.RegularExpressions
				
Public Module Module1
	Public Sub Main()
		
		Dim regex As Regex = New Regex("SN: \d+")
		Dim match As Match = regex.Match("Agen 05, Pembelian SM5.08132166171 Hrg=5500 SUKSES SN: 3778882223. Saldo Rp.(Awal 780700 Akhir 775200)")
		If match.Success Then
	    	Console.WriteLine(match.Value)
		End If

	End Sub
End Module



了解更多:

1. 30分钟正则表达式教程 [ ^ ]

2. http: //www.dotnetperls.com/regex-vbnet [ ^ ]


使用正则表达式 SN \ * *:\ * *(\d *),如下所示:

Use the regex SN\s*:\s*(\d*) like this :
Dim match As Match = Regex.Match(inputstring, "SN\s*:\s*(\d*)",  RegexOptions.IgnoreCase)
	If match.Success Then
	    ' Write value.
	    MessageBox.Show(match.Groups(1)) ' will give 3778882223
	End If


您应该学习RegEx(常规)表达式)

这是文档

perlre - perldoc.perl.org [ ^ ]

结束a很少有工具可以帮助构建和调试RegEx:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]

.NET正则表达式测试程序 - 正则表达式风暴 [ ^ ]

Expresso正则表达式工具 [ ^ ]
You should learn RegEx (Regular Expressions)
Here is documentation
perlre - perldoc.perl.org[^]
End a few tools to help building and debug a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]


这篇关于快速,最好的方式获取单词内容字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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