• 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
va_list customize strings and objects.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

va_list customize strings and objects.


  • Subject: va_list customize strings and objects.
  • From: Mr.Gecko <email@hidden>
  • Date: Fri, 13 Aug 2010 22:24:10 -0500

Hello, I'm wanting to let's say escape strings and objects in a va_list before I use NSString to place the format together into one string. I know that on OS X va_list is just a char * that is an array, so I know I should be able to make one manually in code, but how is the question. I read http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html and that's how I know va_list is a char *. Here is what I have come up with so far, I just need to know how to replace the value of the object with a new one, and the value of the string with the new one, and to just leave everything else the same. I would expect that I'll have to make a a new char * with the arguments and the changes or at least have a reference to the start of the va_list so I can send that back to NSString's initWithFormat:arguments:.

va_list ap;
va_start(ap, format);
if (format==nil)
	return;
NSString *currentFormat = format;
NSRange range = [currentFormat rangeOfString:@"%"];
while (range.location!=NSNotFound) {
	unichar character = [currentFormat characterAtIndex:range.location+1];
	NSLog(@"%C", character);
	switch (character) {
		case '@':
			// Do something with the object.
			break;
		case 's':
			// Do something with the string.
			break;
		default:
			// Leave this alone.
			break;
	}
	currentFormat = [currentFormat substringWithRange:NSMakeRange(range.location+2, [currentFormat length]-(range.location+2))];
	range = [currentFormat rangeOfString:@"%"];
}
NSString *result = [[[NSString alloc] initWithFormat:format arguments:ap] autorelease];
va_end(ap);

I know this is something hard to understand, I hope that code snippet above will help you understand what I'm trying to do.

Any help at all will be greatly appreciated.

Thanks,
Mr. Gecko_______________________________________________

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: va_list customize strings and objects.
      • From: "Mr. Gecko" <email@hidden>
  • Prev by Date: Get an escape sequence out of an NSString
  • Next by Date: Clarification on Associated Objects
  • Previous by thread: Re: Get an escape sequence out of an NSString
  • Next by thread: Re: va_list customize strings and objects.
  • Index(es):
    • Date
    • Thread