Jump to content

Help with StringRegExp


dormmamu
 Share

Recommended Posts

I am reading a line from a text file that contains some information about an archive. I want to retrieve the total file size and number of files.

I have managed to do this with the code below but I was wondering if there was a simpler method using StringRegExp or StringRegExpReplace.

#include <string.au3>
$str = '                             132750002             6 files, 0 folders'

$size = stringstripws($str, 1)
$size = stringmid($size, 1, Stringinstr($size, ' '))

$fcnt = _StringBetween($str, $size, ' files')
$fcnt = stringstripws($fcnt[0], 1)

MsgBox(0,'', 'Size: ' & round(number($size) /1024 /1024) & ' MB' & @crlf & 'Files: ' & $fcnt)

Thanks

Edited by dormmamu
Link to comment
Share on other sites

I am reading a line from a text file that contains some information about an archive. I want to retrieve the total file size and number of files.

I have managed to do this with the code below but I was wondering if there was a simpler method using StringRegExp or StringRegExpReplace.

#include <string.au3>
$str = '                             132750002             6 files, 0 folders'

$size = stringstripws($str, 1)
$size = stringmid($size, 1, Stringinstr($size, ' '))

$fcnt = _StringBetween($str, $size, ' files')
$fcnt = stringstripws($fcnt[0], 1)

MsgBox(0,'', 'Size: ' & round(number($size) /1024 /1024) & ' MB' & @crlf & 'Files: ' & $fcnt)

Thanks

You could do it this way

$str = '                             132750002             6 files, 0 folders'
$aStr = stringsplit(stringstripws($str, 5)," ")
MsgBox(0,'', 'Size: ' & round(number($aStr[1]) /1024 /1024) & ' MB' & @crlf & 'Files: ' & $aStr[2])
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You could do it this way

$str = '                             132750002             6 files, 0 folders'
$aStr = stringsplit(stringstripws($str, 5)," ")
MsgBox(0,'', 'Size: ' & round(number($aStr[1]) /1024 /1024) & ' MB' & @crlf & 'Files: ' & $aStr[2])
You're right I could ;) thanks martin. I looked at the strip double (or more) spaces between words

option but it just didn't click.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...