• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Obtaining the number of characters in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Obtaining the number of characters in a string


  • Subject: Obtaining the number of characters in a string
  • From: Phil Faber <email@hidden>
  • Date: Sun, 20 Jul 2008 12:56:00 +0100

Still struggling with documentation!

Simple task. I have two text fields (text1 & text2) and all I'm trying to achieve is to put into text2 a number specifying how many characters there are in the text in text1.

I started with:

[text2 setStringValue:[text1 stringValue]];

..just to make sure I was on the right track and it successfully placed a copy of the text1 text into text2. Now all I needed was to change the code to put the character count instead.

I looked at the documentation and under NSString I found:

Getting a String’s Length
	• – length
	• – lengthOfBytesUsingEncoding:
	• – maximumLengthOfBytesUsingEncoding:

So I click on 'length' and was told that this 'Returns the number of Unicode characters in the receiver.' Not sure if that's the same thing as just counting characters but changed my code to:

[text2 setStringValue:[text1 length]];

and got ...'warning: passing argument 1 of 'setStringValue:' makes pointer from integer without a cast'

..so assuming this means I was trying to place a number into a text field, I changed the code to:

[text2 setIntValue:[text1 length]];

It compiled and linked fine but the code didn't put anything into text2!

Where am I going wrong?_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Obtaining the number of characters in a string
      • From: Ron Fleckner <email@hidden>
    • Re: Obtaining the number of characters in a string
      • From: Tim Isted <email@hidden>
  • Prev by Date: NSDocument's isDocumentEdited
  • Next by Date: Re: Obtaining the number of characters in a string
  • Previous by thread: Re: NSDocument's isDocumentEdited
  • Next by thread: Re: Obtaining the number of characters in a string
  • Index(es):
    • Date
    • Thread