---
title: "stringWithFormat:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsstring/stringwithformat:"
---

# stringWithFormat:

Returns a string created by using a given format string as a template into which the remaining argument values are substituted.

## Declaration

```occ
+ (instancetype) stringWithFormat:(NSString *) format;
```

## Parameters

- `format`: A format string. See https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html#//apple_ref/doc/uid/20000943 for examples of how to use this method, and https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFStrings/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265 for a list of format specifiers. This value must not be nil. important: Raises an NSInvalidArgumentException if format is nil.

## Return Value

Return Value A string created by using format as a template into which the remaining argument values are substituted without any localization.

## Discussion

Discussion Pass a comma-separated list of trailing variadic arguments to substitute into format. This method invokes init(format:locale:arguments:) without applying any localization. This is useful, for example, when working with fixed-format representations of information that is written out and read back in at a later time. important: When working with text that’s presented to the user, use the localizedStringWithFormat: method, or the initWithFormat:locale: or init(format:locale:arguments:) method, passing current as the locale.

## See Also

### Creating and Initializing Strings

- [string](foundation/nsstring/string.md)
- [init()](foundation/nsstring/init().md)
- [init(bytes:length:encoding:)](foundation/nsstring/init(bytes:length:encoding:).md)
- [init(bytesNoCopy:length:encoding:freeWhenDone:)](foundation/nsstring/init(bytesnocopy:length:encoding:freewhendone:).md)
- [init(characters:length:)](foundation/nsstring/init(characters:length:).md)
- [init(charactersNoCopy:length:freeWhenDone:)](foundation/nsstring/init(charactersnocopy:length:freewhendone:).md)
- [init(string:)](foundation/nsstring/init(string:)-210xa.md)
- [initWithFormat:](foundation/nsstring/initwithformat:.md)
- [init(format:arguments:)](foundation/nsstring/init(format:arguments:).md)
- [initWithFormat:locale:](foundation/nsstring/initwithformat:locale:.md)
- [init(format:locale:arguments:)](foundation/nsstring/init(format:locale:arguments:).md)
- [init(data:encoding:)](foundation/nsstring/init(data:encoding:).md)
- [localizedStringWithFormat:](foundation/nsstring/localizedstringwithformat:.md)
- [localizedUserNotificationString(forKey:arguments:)](foundation/nsstring/localizedusernotificationstring(forkey:arguments:).md)
- [stringWithCharacters:length:](foundation/nsstring/stringwithcharacters:length:.md)
