stringwithformat

How do I set the fill character for displaying numbers (Objective C)

I'm trying to format a string to give me 2 characters for a number, no matter what its value. Right now, I have [NSString stringWithFormat:@"%2d:%2d:%2d",h,m,s)]; and for the values 1, 2, 3, the output is 1: 2: 3 How do I change the spaces to 0's ? ...

Displaying numeric value in label area of iPhone using stringWithFormat

I am new to Objective C and the iPhone SDK, and am trying to figure out the following as a simple example of displaying a numeric result in a label area: label.text = [NSString stringWithFormat: @"%d", 55]; This code above displays the number "55" in the label area. However, the following code results in the display of "0" (with calcu...

comma separated thousand NSString stringWithFormat

Is it possible to display 1000.99 as 1,000.99 using [NSString stringWithFormat:@"£%0.2f", 1000.99] Please guide me if I am not on the right track to achieve this? ...

openURL: with a NSURL containing a formatted NSString isn't working

To open Google Maps with directions, i'm using a formatted NSString inside a NSURL. But it doesn't work with [[UIApplication sharedApplication] openURL:nsurl]; code: NSString * directionsURL = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%@&saddr=%@", @"Hartenseweg 16, Renkum", @"1 Infinte Loop, Cupertino"]; [...

Use stringWithFormat: as a file path in cocoa

Hello, I'm having a problem with a cocoa application that takes the value of a text field, and writes it to a file. The file path is made using stringWithFormat: to combine 2 strings. For some reason it will not create the file and the console says nothing. Here is my code: //Get the values of the text field NSString *fileName = [fileN...

Monotouch stringWithFormat using a URL

I'm trying to learn the MapKit with Monotouch and I'm having difficulty figuring out how to search for an address. I finally found this snippet of Objective-C code that might help but it has a line where they use a URL to get a return value and I have no idea how to use this code in C#: NSString *urlString = [NSString stringWithFormat:...

NSString stringWithFormat - trying to set a label to double digits for single digit numbers

I am trying to have a label display single-digit numbers as double-digit numbers (ie. 1 => 01) . I may be using the wrong method to set the value for the label but the thing is I'm not even sure about that after pouring over Apple's documentation and scouring the internet. [secondsLabel setValue:[NSString stringWithFormat:@"%2d", secon...

NSString stringWithFormat

Hi Guys, I don't know what I am missing here. I am trying to concatenate strings using NSString stringWithFormat function. This is what I am doing. NSString *category = [row objectForKey:@"category"]; NSString *logonUser = [row objectForKey:@"username"]; user.text = [NSString stringWithFormat:@"In %@ by %@", category, logonUser]; The...

Objective-C "miscasting" a string/int using stringWithFormat and %d

Hi, I think this is a relatively simple question, but I don't precisely know what's happening. I have a method that tries to build a string using NSString's stringWithFormat It looks like this: NSString *line1 = [NSString stringWithFormat:@"the car is %d miles away", self.ma]; In the above line "self.ma" should be an int, but in my ...

NSString stringWithFormat swizzled to allow missing format numbered args

Based on this SO question asked a few hours ago, I have decided to implement a swizzled method that will allow me to take a formatted NSString as the format arg into stringWithFormat, and have it not break when omitting one of the numbered arg references (%1$@, %2$@) I have it working, but this is the first copy, and seeing as this meth...

How to append the string variables using stringWithFormat method in Objective-C

Hi Guys, I want to append the string into single varilable using stringWithFormat.I knew it in using stringByAppendingString. Please help me to append using stringWithFormat for the below code. NSString* curl = @"https://invoices?ticket="; curl = [curl stringByAppendingString:self.ticket]; curl = [curl stringByAppendingString:@"&apikey...

Reusing NSMutableString correctly on the iPhone

Using objective-c on the iPhone, what is wrong with this code? Is it leaking memory? Why? How would I do this correctly? NSMutableString *result = [NSMutableString stringWithFormat:@"the value is %d", i]; ... then later in my code... I might need to change this to: result = [NSMutableString stringWithFormat:@"the value is now %d", i...

Invalidate NSTimer not working

I am have created a timer where I convert the remaining time to a string with a format of:"mm:ss" and when the string value of the time is 00:00 I would like to invalidate the timer. For some reason it doesn't work, even when I log the remaining time I see the the value has the correct format so I don't know why my "if" branch in "countT...