Re: Limiting NSString length without knowing the length
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.