Jump to content
Sign in to follow this  
asgarcymed

How to "subtract strings"?

Recommended Posts

asgarcymed

The mathematical operators are easy to use and everybody knows:

$a=10

$b=1

$a + $b = 11

$a - $b = 9

However, if variables are strings rather than numbers, sometimes is confusing...

$a = "AAAAAAAZZZZZZZZZZZZZZZ"

$b = "ZZZZZZZZZZZZZZZ"

$a & $b (the correct; not $a + $b because no numbers!) = "AAAAAAAZZZZZZZZZZZZZZZAAAAAAAZZZZZZZZZZZZZZZ"

My question is -How to subtract characters using string variables?:

«$a -$b» = "AAAAAAA" (what is the correct expression, instead of «$a -$b»?)

Regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites
BrettF

Maybe...

MsgBox (0, "", _StringLikeMath ("aaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxx", "*", 10))

Func _StringLikeMath ($a, $op, $b)
    Local $ret
    If $op = "-" Then
        $ret = StringReplace ($a, $b, "", 1, 1)
    ElseIf $op = "+" Then
        $ret = $a & $b
    ElseIf $op = "*" Then
        For $i = 1 to $b
            $ret &= $a
        Next
    ElseIf $op = "/" Then
        $ret = "Not sure what to do... ERROR! EEP! =P"
    EndIf
    Return $ret
EndFunc
Edited by Bert

Share this post


Link to post
Share on other sites
asgarcymed

Thanks!

:)


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites
BrettF

Share this post


Link to post
Share on other sites
asgarcymed

Your code made me to learn what I was looking for and much more! A big thank you!


MLMK - my blogging craziness...

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  

×