Concatenating Strings

So:

In Applescript, if I want to concatenate strings, I just use an ampersand:

set a to “hello” & " " & “world!”

In ApplescriptObjC, what’s the format for that?

property newClient : missing value
property sapNumber : missing value
property workOrder : missing value

property testView : missing value


on setWindowValueFields_(sender)
    set newClientValue to newClient's stringValue()
    set sapNumberValue to sapNumber's stringValue()
    set workOrderValue to workOrder's stringValue()
    testView's setString_(newClientValue) + (sapNumberValue) + (workOrderValue)
end setWindowValueFields_

I’ve tried:

   testView's setString_(newClientValue) & (sapNumberValue) & (workOrderValue)

and

 testview's setString_((newClientValue) & (sapNumberValue) & (workOrderValue))

all with no luck. It either doesn’t return a value at all or it returns only the first value. I can’t seem to find the right documentation on this – could someone help?

Thanks.

Hi,

the Cocoa way to concatenate multiple strings is the method stringWithFormat_() of NSString.
%@ is a placeholder for an object.


set concatentedString to current application's NSString's stringWithFormat_("%@%@%@", newClientValue, sapNumberValue, workOrderValue)
testView's setString_(concatentedString)

Note: the plus character is always the numeric add operator (both in AppleScript and ObjC).

That worked like a charm.

Many thanks.

I did look at stringWithFormat in the NSString dictionary, but it never made it clear that was how strings were concatenated.

Thanks again.