35

i have a string strored in str variable i want to find string length which is available in str variable

i hav tried with strlen(str); its not working...

3 Answers 3

81

If your string is a C-String, then you can use strlen(str).

If it is a NSString *str, then you can use NSUInteger length = [str length];

1
  • But '[str length]' don't contain space's length.
    – ylgwhyh
    Aug 7, 2016 at 8:58
10

What type is your string? If it's an NSString, you find the length like this:

int len = [myString length];

But it will be different if your string is not an NSString.

0

Use length method, like this:

NSString *myString = @"Hello World";
int myLength = [myString length]; //myLength is now 11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.