Jump to content

How to "subtract strings"?


Recommended Posts

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...
Link to comment
Share on other sites

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

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