Jump to content

If string contains a letter.


Klexen
 Share

Recommended Posts

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.

Link to comment
Share on other sites

$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 by oMBra
Link to comment
Share on other sites

$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!
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...