I am doing a Cocoa tutorial where I need to count the characters in a field, then output something like 'the_string_i_am_count' has 21 characters.
I have managed to get the string, count it, and output the count but I have no idea how to output the count along with the string and the other info.
How would I do this?
-(IBAction)countCharacters:(id)sender
{
//i had to connect this to the class also to make it get the value.
//NSString *string = [inputField stringValue];
//get the number of chars
NSUInteger length = [[inputField stringValue] length];
[outputField setIntValue:length]; //string];
//[outputField setStringValue: @"'s' has %d characters.", string, length];
}
Semi working code:
-(IBAction)countCharacters:(id)sender
{
//i had to connect this to the class also to make it get the value.
NSString *string = [inputField stringValue];
//get the number of chars
NSUInteger length = [[inputField stringValue] length];
[outputField setStringValue:[NSString stringWithFormat:@"'%s' has %d characters.", string, length]];
}