+= and ++?

Hello

Does += and/or ++ exist in Xojo?
Cannot seem to find it in the documentation.

It’s way cleaner to write

string1 += string2

instead of

string1 = string1 + string2

Thanks!

No, they don’t exist in Xojo.

Julen

Thanks for the fast reply Julen!

You could use Extends to get the += functionality:

Add this method to a module:

Sub Append(Extends ByRef s1 As String, s2 As String) s1=s1+s2 End Sub

Then you can use it this way:

string1.Append String2

“Append” is just the name of the method, it can be shortened of course.

Julen

But don’t do that where speed is critical as function calls come with an overhead, at least in 32 bit.

I use Keyboard Maestro on the Mac to retype my code when those keystrokes are used. If I type “i opt-plus opt-plus”, it replaces it with i = i + 1.

[quote=313350:@Mathias Maes]It’s way cleaner to write

string1 += string2

instead of

string1 = string1 + string2

Nope.

[quote=313354:@Julen Ibarretxe Uriguen]You could use Extends to get the += functionality:

Add this method to a module:

Sub Append(Extends ByRef s1 As String, s2 As String) s1=s1+s2 End Sub

Then you can use it this way:

string1.Append String2

“Append” is just the name of the method, it can be shortened of course.

Julen[/quote]

Yeah I know, but that seems confusing, as most developers would expect the ‘Append’ method on Arrays or other list types. Or maybe on more complex types like stringbuilder in C#. Not usualy on basic data types.

[quote=313355:@Kem Tekinay]But don’t do that where speed is critical as function calls come with an overhead, at least in 32 bit.

I use Keyboard Maestro on the Mac to retype my code when those keystrokes are used. If I type “i opt-plus opt-plus”, it replaces it with i = i + 1.[/quote]

That’s a great idea! Thanks!

IF you were to make a function… (which for reasons stated above I don’t suggest you do)… but
I’d name it CONCAT instead of APPEND

[quote=313379:@Dave S]IF you were to make a function… (which for reasons stated above I don’t suggest you do)… but
I’d name it CONCAT instead of APPEND[/quote]

That is indeed a better name. But I won’t make a function ideed.