What's the difference between single and double quotes in Objective-C?
Posted
by Alex Mcp
on Stack Overflow
See other posts from Stack Overflow
or by Alex Mcp
Published on 2010-06-06T00:57:19Z
Indexed on
2010/06/06
1:02 UTC
Read the original article
Hit count: 289
objective-c
I'm working through a book exercise to generate some random serial number, and here's my function:
NSString *randomSerialNumber = [NSString stringWithFormat:@"%c%c%c%c%c",
'0' + random() % 10,
'A' + random() % 26,
'0' + random() % 10,
'A' + random() % 26,
'0' + random() % 10];
This works and has an output like: 2J6X7. But before, the 0s and As I had wrapped in double quotes, and an example output was 11764iÒ˜. What did I do wrong my first time around, and why did using single quotes fix it?
© Stack Overflow or respective owner