# Strings: initWithFormat



## Dominyo (Jan 30, 2003)

I'm a complete newbie to Cocoa and Objective-C. I'm currently writing a program with a string that needs to hold the contents of a variable.


```
NSMutableString *string1 = [[NSMutableString alloc] initWithFormat:@"%i", variable1];
```

Works fine, until the variable changes, and the string doesn't. Anyway to update the string to hold the new contents of the variable? I've tried setString:, but that doesn't work, and there's no setStringWithFormat:.


----------



## Just_Me (Jan 31, 2003)

Try this:

string1 = [NSString stringWithFormat: @"%i", variable1];


----------



## Dominyo (Jan 31, 2003)

Wow, thanks. Feel so stupid


----------

