Solved

How to find multiple occurance of a word in a string

Posted on 2011-02-26
2
532 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
Comment Utility
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now