Sign in to follow this  
Followers 0
asgarcymed

How to "subtract strings"?

5 posts in this topic

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



#2 ·  Posted (edited)

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

Thanks!

:)


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

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  
Followers 0