Klexen Posted October 14, 2008 Posted October 14, 2008 Is there a way to take a string contained in a variable, check to see if it starts with a number. If it doesn't start with a number set the string to something else? Here is some of my code... $readtext = _IEBodyReadText($oIE) ;Black $BlackPercent = StringMid($readtext,470,4) $BlackPages = StringMid($readtext,665,4) ;Cyan $CyanPercent = StringMid($readtext, 770,4) $CyanPages = StringMid($readtext, 963,4) ;Magenta $MagentaPercent = StringMid($readtext,1070,4) $MagentaPages = StringMid($readtext,1263,4) ;Yellow $YellowPercent = StringMid($readtext,1370,4) $YellowPages = StringMid($readtext,1563,4) Basically what this does is opens the page that displays printer ink statistics, and reads the stats, then I can do with the values what I want. However, if the ink is out, it does not display the stats, so of course the string it grabs is all messed up. So if the string does not start with a number, I want to replace string contents with the word "out" If anyone can help me with this I would greatly appreciate it.
oMBRa Posted October 14, 2008 Posted October 14, 2008 (edited) $String = StringRegExp(StringLeft($YOUR_STRING_HERE, 1), '[0-9]', 1);replace $YOUR_STRING_HERE with the variable that contains your string contents If @error == 1 Then $YOUR_STRING_HERE = 'out';replace $YOUR_STRING_HERE with the variable that contains your string contents EndIf Edited October 14, 2008 by oMBra
Klexen Posted October 14, 2008 Author Posted October 14, 2008 $String = StringRegExp(StringLeft($YOUR_STRING_HERE, 1), '[0-9]', 1);replace $YOUR_STRING_HERE with the variable that contains your string contents If @error == 1 Then $YOUR_STRING_HERE = 'out';replace $YOUR_STRING_HERE with the variable that contains your string contents EndIf Worked GREAT. Thanks a lot man!
Robjong Posted October 14, 2008 Posted October 14, 2008 (edited) You had what you needed already, anyways this also works. Edit: javascript error $sString = 'Some String' If Not StringRegExp($sString, '\A\d') Then ; string does not start with an integer $sString = '1. Another String' EndIf ConsoleWrite($sString & @CRLF) Edited October 15, 2008 by Robjong
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now