Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 9-Aug-16 18:37pm

Try this:
VB.NET
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

Learn more:
1. The 30 Minute Regex Tutorial[^]
2. http://www.dotnetperls.com/regex-vbnet[^]
 
Share this answer
 
v3
Comments
Karthik_Mahalingam 10-Aug-16 0:39am    
5!Clean
Peter Leow 10-Aug-16 0:43am    
Thank you, Karthik.
ulungss 10-Aug-16 4:42am    
it's work, great . thank peter.
Use the regex SN\s*:\s*(\d*) like this :
VB.NET
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
 
Share this answer
 
v2
Comments
ulungss 10-Aug-16 4:43am    
thanks mehdi, work great and for second choice.
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[^]
 
Share this answer
 
Comments
ulungss 10-Aug-16 4:43am    
thanks for reference....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900