Solved

How to find multiple occurance of a word in a string

Posted on 2011-02-26
2
536 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

726 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