Thanks to all who helped me with this challenge of obtaining the number of characters in a string.

On 20 Jul 2008, at 13:12, Tim Isted wrote:
Try using

[text2 setStringValue:[NSString stringWithFormat:@"%i", [[Field1 stringValue] length]]];

Using setIntValue on a text field won't set the text field's stringValue to be a string from that int.

That worked perfectly - thanks Tim.



On 20 Jul 2008, at 13:16, Ron Fleckner wrote:

Still struggling with documentation!

That might be because the documentation makes the reasonable assumption that you already know how to use C and Objective-C.

You're not recognising the difference between the data types 'int' and 'pointer to object'. The text field expects a pointer to an NSString. Telling it to setIntValue:someInt is just you hoping it'll work.

What you need to do is [text2 setStringValue:[NSString stringWithFormat:@"%d", [text1 length]]];

You should read the documentation, paying attention to method return types and etcetera. Also, bone up on basic C. It will help a lot.

I'm trying! Honest! I've studied 'Learn C for Cocoa' at http://cocoadevcentral.com/articles/000081.php , and a C programming book, as well as looking up stuff on the Web but it's a very slow process. The fact that I'm dyslexic doesn't help (although that's not a good excuse) as I need to go over things again and again to 'get' them ... although once I've 'got it', it tends to stay put! Getting there. Slowly.



On 20 Jul 2008, at 14:41, Andy Lee wrote:
On Jul 20, 2008, at 8:12 AM, Tim Isted wrote:
Try using

[text2 setStringValue:[NSString stringWithFormat:@"%i", [[textField1 stringValue] length]]];

Using setIntValue on a text field won't set the text field's stringValue to be a string from that int.

I believe this is incorrect.  Try simply

[text2 setIntValue:[[text1 stringValue] length]];

The original mistake was using [text1 length], which asks the text *field* for its length (no such method) instead of asking the text field's *string*.

Interesting. Although Tim's original suggest did work (so it wasn't 'wrong' as such...) your simpler version also works and seems much neater as it simply asks for the length of the string value of text1.

Thanks everyone!

Phil
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to