Linux world
Linux world

Reputation: 3768

how to find string length using strlen in objective c

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...

Upvotes: 37

Views: 66191

Answers (3)

vodkhang
vodkhang

Reputation: 18741

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];

Upvotes: 83

Cokegod
Cokegod

Reputation: 8434

Use length method, like this:

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

Upvotes: 0

Silromen
Silromen

Reputation: 1131

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.

Upvotes: 10

Related Questions