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

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

##### Share on other sites

Thanks!

MLMK - my blogging craziness...

##### Share on other sites

Thanks!

Just use the part you need in the actual function I created... The rest was a bit of fun, so you could get the general idea

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

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...