Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to find multiple occurance of a word in a string

Posted on 2011-02-26
2
Medium Priority
?
539 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 1000 total points
ID: 34988899
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1000 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

Independent Software Vendors: 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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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…

722 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