Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
need help from a programmer
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Raz0rEdge" data-source="post: 1527519" data-attributes="member: 110816"><p>To concatenate two strings, you have a couple of options. One is to use to use a <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/Reference/Reference.html" target="_blank">NSMutableString</a>, and the other is to string with the <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html" target="_blank">NSString</a>, but create a new one..</p><p></p><p>So for example..</p><p>[CODE]</p><p>NSString *first = @"Hello ";</p><p>NSString *second = @"World";</p><p></p><p>NSString *result = @"";</p><p>result = [result stringByAppendingString:first];</p><p>result = [result stringByAppendingString:second];</p><p>[/CODE]</p><p></p><p>The NSString result now contains "Hello World" in it..</p><p></p><p>The second option is</p><p>[CODE]</p><p>NSString *second = @"World";</p><p>NSMutableString *result = @"Hello ";</p><p></p><p>result = [result appendString:first];</p><p>[/CODE]</p><p>The NSMutableString result now contains "Hello World".</p><p></p><p>You might want to read up on Mutable and Immutable objects and see the pros and cons about using one over the other..</p></blockquote><p></p>
[QUOTE="Raz0rEdge, post: 1527519, member: 110816"] To concatenate two strings, you have a couple of options. One is to use to use a [URL="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/Reference/Reference.html"]NSMutableString[/URL], and the other is to string with the [URL="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html"]NSString[/URL], but create a new one.. So for example.. [CODE] NSString *first = @"Hello "; NSString *second = @"World"; NSString *result = @""; result = [result stringByAppendingString:first]; result = [result stringByAppendingString:second]; [/CODE] The NSString result now contains "Hello World" in it.. The second option is [CODE] NSString *second = @"World"; NSMutableString *result = @"Hello "; result = [result appendString:first]; [/CODE] The NSMutableString result now contains "Hello World". You might want to read up on Mutable and Immutable objects and see the pros and cons about using one over the other.. [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
need help from a programmer
Top