• 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
Re: Obtaining the number of characters in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obtaining the number of characters in a string


  • Subject: Re: Obtaining the number of characters in a string
  • From: Tim Isted <email@hidden>
  • Date: Sun, 20 Jul 2008 13:12:41 +0100

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.

Tim


On 20 Jul 2008, at 12:56, Phil Faber wrote:

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

_______________________________________________

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: Andy Lee <email@hidden>
    • Re: Obtaining the number of characters in a string
      • From: Graham Cox <email@hidden>
References: 
 >Obtaining the number of characters in a string (From: Phil Faber <email@hidden>)

  • Prev by Date: Obtaining the number of characters in a string
  • Next by Date: Re: Obtaining the number of characters in a string
  • Previous by thread: Obtaining the number of characters in a string
  • Next by thread: Re: Obtaining the number of characters in a string
  • Index(es):
    • Date
    • Thread