nsstring

Displaying percentage using NSString

How do we display percentage character in objective-c? I am using this: [NSString localizedStringWithFormat:@"%.2f %", percentageQs] But for some reason, it doesn't recognize the %. thought i could escape it using this \ but i was so wrong. ...

converting NSString to precise number for performSelector: afterDelay:

I am communicating with a webservice to retrieve a numerical value that comes into my function as an NSString. This number tells me the precise amount of time to wait until I perform another action, and it is critical that it be precise. As an example, if the string is "89283", then this means I must wait 89.283 seconds. So I'd like...

Concatenating two NSStrings separated by a CRLF

Sorry for the dumb question. I have two NSStrings and I want to create a third that is the first string plus a new line plus the second string. I know this must be easy but I am banging my head looking for it. Ultimately I want the resulting string to display correctly in a table view cell. Regards Dave ...

What is the best way to define string constants in an objective-c protocol?

I have defined a protocol that all my plug-ins must implement. I would also like the plug-ins to all use certain strings, like MyPluginErrorDomain. With integers this is quite easily achieved in an enum, but I can't figure out how to do the same with strings. Normally, in classes I would define extern NSString * const MyPluginErrorDoma...

How do I match non-ASCII characters with RegexKitLite?

I am using RegexKitLite and I'm trying to match a pattern. The following regex patterns do not capture my word that includes N with a titlde: ñ. Is there a string conversion I am missing? subjectString = @"define_añadir"; //regexString = @"^define_(.*)"; //this pattern does not match, so I assume to add the ñ //regexString = @"^def...

cocoa: NSString not removing all the characters

I have an int and for some reason it isn't working after 16 or so. Here's my code: NSArray *sortedArray; sortedArray = [doesntContainAnother sortedArrayUsingFunction:firstNumSort context:NULL]; int count2 = [sortedArray count]; //NSLog(@"%d", count2); int z = 0; while (z < count2) { NSString *myString = [sortedArray objectAtIndex:z]...

Autocorrect NSString on iPhone

Basically what I want to do is to use Cocoa's autocorrection feature on NSString. E.g. [string autocorrect] would return what it text field shows in a popup Is it possible? ...

UIAlertView Messages

Trying to include a instance variable in a message that a UIAlertView Shows. lostAlert = [[UIAlertView alloc] initWithTitle:@"Sorry" message:(@"You Were Wrong, the correct structure was %@", structureName) delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; however, when the Alert is shown, no message is shown. Any i...

CamelCase to underscores and back in Objective-C

I'm looking for a simple, efficient way to convert strings in CamelCase to underscore notation (i.e., MyClassName -> my_class_name) and back again in Objective C. My current solution involves lots of rangeOfString, characterAtIndex, and replaceCharactersInRange operations on NSMutableStrings, and is just plain ugly as hell :) It seems ...

Problem with Extracting NSString from TXT

I am trying to create one long string from a text file. This is the code that I currently have. I do not really understand the encoding and I tried to research but found nothing. This is the line of code that I have: NSString* data = [[NSString alloc] initWithContentsOfFile:@"12thnew.txt" encoding: error:NULL]; When I entered the enco...

Reusing NSString in the same .m file

I have a string (currently defined in my .h file) that I'd like to fill and reuse in my .m file. Here's the setup: User clicks btnA in my interface btnA runs a method (buttonAClicked) that sets the NSString's value to "foo" USer clicks btnB in my interface btnB runs a method (buttonBClicked) that returns the value of the NSString (eg:...

NSArray item to NSString

In a method, I'm having following code: NSString* tempString = (NSString*)arg; NSArray* notificationDetails = [tempString componentsSeparatedByString:@"##"]; NSString* tempString1 = [notificationDetails objectAtIndex:2]; . . . . . . NSLog(tempString1); When I compile the code, its compiling without any error and warning. But while ru...

Is it possible to include a quotation mark as part of an nsstring?

I have a label that displays inches. I would like to display the number with the inch symbol (") or quotation mark. Can I do this with an nsstring? Thanks! ...

static NSString usage vs. inline NSString constants

In Objective-C, my understanding is that the directive @"foo" defines a constant NSString. If I use @"foo" in multiple places, the same immutable NSString object is referenced. Why do I see this code snippet so often (for example in UITableViewCell reuse): static NSString *CellId = @"CellId"; UITableViewCell *cell = [tableView dequeueR...

Don't have the right syntax when comparing strings in iPhone

I am trying to compare the following values: gType = [[UILabel alloc]init]; if (gType = [NSString string:@"BUSINESS"]) { I get a warning that 'NSString' may not respond to '+string:' I am unsure what is wrong. gType is a value that I populate from a db query. Other text values from the same query show up fine in a UITableView, so...

IPhone Float to String issue

I can't live another day without knowing why this is happening. I have an iPhone application using Corelocation and here is the issue: GPSLocation.m - sends long/lat coordinates which are floats to class UserSettings.m (which is a singleton class) _ UserSettings.m - Then cast the values into a predefined strings from a f...

Create constant NSString from constant CFStringRef

I am attempting to create a Cocoa Framework that is an object-oriented wrapper around a procedural framework written in the Core Foundation. The procedural framework has a number of constants that are all defined as extern CFStringRef constantName. How should I create NSString constants that directly map to the procedural constants so t...

iPhone + NSString error

Hello, I have static NSString as below: static NSString *bowlerName; In the code I am assigning it with some value as below: -(void)setBowlerSpecifications:(int)playerId { Player *objPlayer = [CricketManagementDAL getBowlerSpecification :playerId]; [objPlayer retain]; bowlerSpecialSkill = objPlayer.specialSkill; bowlerT...

iPhone Google Data API HTTP Protocol, Auth Token from string

Google Docs returns a long 3 line string when supplied with credentials. This is the format SID=stuff... LSID=stuff... Auth=long authorization token if I have it stored in NSString, what is the best function to trim all the way up to the "=" behind Auth, and keep the rest? NSData *returnedData = [NSURLConnection sendSynchr...

Converting NSString to Currency - The Complete Story

After over a day of poking around with this problem I will see if I can get some help. This question has been more or less asked before, but it seems no one is giving a full answer so hopefully we can get it now. Using a UILabel and a UITextView (w/ number keyboard) I want to achieve an ATM like behavior of letting the users just type t...