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
Solved

How to find multiple occurance of a word in a string

Posted on 2011-02-26
2
534 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…

792 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