Link to home
Start Free TrialLog in
Avatar of Michael Roodt
Michael Roodt

asked on

How to find a random number in string

Hi,

I can't seem to find a way for searching for  random number in a string. for example

"150 Opening BINARY mode data connection.
226 Transfer complete
ftp: 5590252 bytes sent in 9.45Seconds 591.31Kbytes/sec."

I need to find the number that is in bold above which could be a different number every time and be placed in a different position. It will however, always be after  "ftp: ". I then need to assign that number to a variable int.

Can anyone help on this please?

Thanks
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

The line doesn't always start with "ftp:"?  i.e., it could sometimes be "Some other stuff ftp: 123345 etc etc"?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The one caveat to tgerbert's pattern, and I don't think it will come to play here, is that if the number following "ftp: " were not followed by a space and had a string immediately following it (e.g.  "ftp: 5590252bytes"), then the match would fail due to the use of the word boundary at the end of the pattern. Again, I don't perceive that to be an issue here  = )