Solved

How to find multiple occurance of a word in a string

Posted on 2011-02-26
2
533 Views
Last Modified: 2012-05-11
Hi,

I'm trying to search through the following string:

150 Opening ASCII mode data connection for stra.txt
226 Transfer complete
ftp: 568180 bytes sent in 1.06Seconds 535.01Kbytes/sec.

ftp> jj
200 PORT command successful
150 Opening ASCII mode data connection for .n/a
226 Transfer complete
ftp: 749238 bytes sent in 0.91Seconds 826.97Kbytes/sec.
ftp> impu
200 PORT command successful
150 Opening ASCII mode data connection for j.txt
226 Transfer complete
ftp: 1437528 bytes sent in 2.05Seconds 702.26Kbytes/sec.

I wanted to retrieve the value  of the bytes sents after "ftp:" With help from other experts I managed to do this via the attached code.  What I would like is to use this code below to get every occurance of the bytes sent as at the moment  I think it only finds the first occurance.

Many thanks
Dim a As Match = Regex.Match(s, "(?<=ftp: *)\d+")
                If a.Success Then
                    value = Convert.ToInt32(a.Value)

                Else
                    ' Do nothing
                End If

Open in new window

0
Comment
Question by:Michael Roodt
2 Comments
 
LVL 9

Accepted Solution

by:
sshah254 earned 250 total points
ID: 34988899
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 34989685
Alternatively, you can use the Matches() function, and iterate through the resulting MatchCollection object.
Dim a As MatchCollection = Regex.Matches(s, "(?<=ftp: *)\d+")

For Each m As Match In a
     value = Convert.ToInt32(m.Value)
Next

Open in new window

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question