Maybe I haven't looked hard enuf, but cannot find a command that extracts a number from a string.
My string may be '5 inch' or '5 cm' and I wish to do calculations with it, so I only need the 5.
regards demac
number in a string
Moderators: Dorian (MJT support), JRL
Well, here's a script that removes non-numerics from a string. So maybe this will help:
http://www.mjtnet.com/forum/viewtopic.p ... ber+string
Or use VBScript's regular expressions. This script extracts all numerics from a string:
VBSTART
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(strng)
For Each Match in Matches
RetStr = RetStr & Match.Value
Next
RegExpTest = RetStr
End Function
VBEND
Let>MyString=Today is 9th March 2005
VBEval>RegExpTest("(\d+)","%MyString%"),numbers
MessageModal>numbers
If you run that without modification the message box will display 92005.
http://www.mjtnet.com/forum/viewtopic.p ... ber+string
Or use VBScript's regular expressions. This script extracts all numerics from a string:
VBSTART
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(strng)
For Each Match in Matches
RetStr = RetStr & Match.Value
Next
RegExpTest = RetStr
End Function
VBEND
Let>MyString=Today is 9th March 2005
VBEval>RegExpTest("(\d+)","%MyString%"),numbers
MessageModal>numbers
If you run that without modification the message box will display 92005.
MJT Net Support
[email protected]
[email protected]
Thanks for the quick response.
I would like to point out that some macro programs have a command to do this (e.g.macromania) . However, I still prefer scheduler for many reasons.
Those macro programs that I've tried don't do enough string handling operations and also few involving character codes.
I miss the old Microsoft Basic which did it all.
regards demac
I would like to point out that some macro programs have a command to do this (e.g.macromania) . However, I still prefer scheduler for many reasons.
Those macro programs that I've tried don't do enough string handling operations and also few involving character codes.
I miss the old Microsoft Basic which did it all.
regards demac