Hi to all:
I have a string Like this:
Msg = "ffff error msg 0081456378390 00827894546738"
I would Like to extract from this string all the values that start by 0081 and 0082.
With way i can do this?
Thanks
Printable View
Hi to all:
I have a string Like this:
Msg = "ffff error msg 0081456378390 00827894546738"
I would Like to extract from this string all the values that start by 0081 and 0082.
With way i can do this?
Thanks
you can do that with regex:
Code:Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Msg As String = "ffff error msg 0081456378390 00827894546738"
For Each m As Match In New Regex("008(1|2)\d+").Matches(Msg)
MsgBox(m.Value)
Next
End Sub
End Class
Split the string on spaces. If the values always occur in the same positions then use the index in the resulting array to get them. Otherwise loop through the array for those that start with the required pattern.
Hi .Paul:
Your code work perfectly, but i think it cacth all "0081" and "0082" string correct? In this case i just cacth always the last message, i this case "0082" because is the last string...It's correct?
yes it catches all "0081" and "0082" values, as you asked for...
Ok...but i can't have both values (0081 and 0082 strange no? do you had test?) and the first "0081" don't return all message if i have a message like this:
00812563695869d085f526
The code return: "00812563695869"
do you know why?
Code:New Regex("008(1|2)\w+")
PERFECT...
Thanks a lot for your help...
HI:
Sory return to the post again but could i Cacth more than one value:
We have this:
For Each m As Match In New Regex("008(1|2)\w+").Matches(msg)
for catch 0081 and 0082...If i have in the message 0051 and 0070 could i put in the line more this two conditions?
I had try a few thinks but without exit!
Thanks
Code:New Regex("00(81|82|51|70)\w+")
Fantastic...thanks a lot!