• 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: Limiting NSString length without knowing the length
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Limiting NSString length without knowing the length


  • Subject: Re: Limiting NSString length without knowing the length
  • From: MacInsight <email@hidden>
  • Date: Thu, 13 Feb 2003 11:45:02 +0100

Hi,

Am Donnerstag, 13.02.03 um 10:40 Uhr schrieb Jeffrey Mattox:

Executive summary:

Is there a NSString method that will truncate a string to a specified length without me having to know its length beforehand?
(...)
Unless I find a better way, this is my solution (convert to a C string, limit the length, and then convert back to NSString):

char theCString[30];
sprintf(theCString,"%.20s",[string1 cString]); // limit
string2 = [NSString stringWithFormat:@"OLD: %@",
[NSString stringWithCString:theCString]];


Give this a try:

NSString* string4 = [NSString stringWithFormat:@"OLD: %@", [string1 substringToIndex:([string1 length] > 20) ? 20 : [string1 length]]];


hth,
Dirk Stegemann
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Limiting NSString length without knowing the length (From: Jeffrey Mattox <email@hidden>)

  • Prev by Date: Limiting NSString length without knowing the length
  • Next by Date: [Newbie] NSOutlineView and icons
  • Previous by thread: Limiting NSString length without knowing the length
  • Next by thread: Re: Limiting NSString length without knowing the length
  • Index(es):
    • Date
    • Thread