Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSString Troubles

NSString Troubles
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Apr 16, 2004, 04:56 PM
 
Hey guys,

I'm trying to append a string to another string in the below code:

Code:
- (void)colorWellChanged:(id)sender { NSString *hexSymbol = [NSString stringWithFormat:@"#"]; NSString *hex = [self colorToHTMLColorCode:[sender color]]; NSLog(@"My Hex Is: %@", hex); [hexSymbol stringByAppendingString:hex]; [hexTextField setStringValue:hexSymbol]; }
So I run the app, it gets the correct values (the hex), but in the text field, only the hexSymbol string is shown (#). What I am wanting is for the hex value to be added after the #. Any ideas what I'm doing wrong?

Thanks,
Oliver
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Apr 16, 2004, 05:16 PM
 
make it hexSymbol = [hexSymbol stringByAppendingString:whatever];

while you're at it, you could delete the first line and make the second to last one:
hexSymbol = [NSString stringWithFormat:@"#%@", hex];
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 16, 2004, 05:20 PM
 
Remember, stringByAppendingString: is an NSString method, not NSMutableString. As such, it can't modify the receiver. It returns an autoreleased string that contains the text of the receiver as well as the argument.

So what you want is hexSymbol = [hexSymbol stringByAppendingString:hex]. Or you could just go with an NSMutableString to begin with.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Apr 16, 2004, 05:28 PM
 
Hey thanks guys, worked great.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2