Sign in to follow this  
Followers 0
seanrintel

Extracting Numbers From Strings And Then Comparing The Numbers

6 posts in this topic

G'day,

Is it possible to extract numbers from two strings (e.g. from window titles) and then compare those two numbers to find which is bigger? Something like this:

$Title1 = $WinList[1][0]
$Title2 = $WinList[2][0]

$Number1 = Some operation to extract the number from $Title1 and make it a usable integer
$Number2 = Some operation to extract the number from $Title2 and make it a usable integer

If $Number1 < $Number2 Then
; Do something
    
ElseIf $Number1 > $Number2 Then
       ; Do something else

EndIf

Any help would be greatly appreciated.

Until anon,

Sean

Share this post


Link to post
Share on other sites



how are these string formatted, if you could paste some sample string here it'd be easier to help find a solution


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

G'day Don,

how are these string formatted, if you could paste some sample string here it'd be easier to help find a solution

There are 24 possible window titles all in this format: "suny1", "suny2", "suny3" ... "suny24".

Until anon,

Sean

Share this post


Link to post
Share on other sites

$str1 = "suny12"
$str2 = "suny20"

$int1 = StringTrimLeft( $str1, 4 )
$int2 = StringTrimLeft( $str2, 4 )

;compare the ints and do whatever else here

StringTrimLeft(), as i used it here, wioll remove the 4 leftmost characters from the string leaving only the integer part remaingin. Check out the helpfile in StringTrimLeft adn StringTrimRight for more details.

hope this helps


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

quick and dirty but it extracts 25 from Un25titled

$Num=""

$winTitle="Un25titled"

For $i = 1 to StringLen($winTitle)

$char=StringMid($winTitle,$i,1)

if ASC($char) < 58 then $Num=$Num & $char

Next

msgbox(0,"",$Num)

Rauto

Share this post


Link to post
Share on other sites

G'day all,

Thanks for the suggestions. Both were helpful, Don's especially.

Thanks,

Sean

Share this post


Link to post
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
Sign in to follow this  
Followers 0