|
-
May 23rd, 2013, 06:20 PM
#1
Thread Starter
Frenzied Member
Extract values from a string
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
Last edited by sacramento; May 24th, 2013 at 08:04 AM.
Reason: RESOLVED
-
May 23rd, 2013, 06:28 PM
#2
Re: Extract values from a string
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 23rd, 2013, 06:29 PM
#3
Re: Extract values from a string
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.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 24th, 2013, 03:45 AM
#4
Thread Starter
Frenzied Member
Re: Extract values from a string
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?
-
May 24th, 2013, 04:16 AM
#5
Re: Extract values from a string
yes it catches all "0081" and "0082" values, as you asked for...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 24th, 2013, 06:24 AM
#6
Thread Starter
Frenzied Member
Re: Extract values from a string
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?
-
May 24th, 2013, 08:02 AM
#7
Re: Extract values from a string
Code:
New Regex("008(1|2)\w+")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 24th, 2013, 08:04 AM
#8
Thread Starter
Frenzied Member
Re: Extract values from a string
PERFECT...
Thanks a lot for your help...
-
May 25th, 2013, 12:16 PM
#9
Thread Starter
Frenzied Member
Re: Extract values from a string
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
-
May 25th, 2013, 12:48 PM
#10
Re: Extract values from a string
Code:
New Regex("00(81|82|51|70)\w+")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 25th, 2013, 02:50 PM
#11
Thread Starter
Frenzied Member
Re: Extract values from a string
Fantastic...thanks a lot!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|