Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 640
Linux world Avatar asked Oct 02 '10 14:10

Linux world


People also ask

How to check length of string in objective C?

int len = [myString length];

Can we use strlen with string?

For C++ strings, there's no reason to use strlen . Just use string::length : Clarity: The length() (or size() ) member functions unambiguously give back the length of the string.

What is the difference between strlen and length?

Evaluation Size: sizeof() is a compile-time expression that gives the size of a type or a variable's type. It doesn't care about the value of the variable. strlen() on the other hand gives the length of a C-style NULL-terminated string and size() also returns the length of the specified string.


2 Answers

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

like image 115
vodkhang Avatar answered Oct 08 '22 16:10

vodkhang


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.

like image 32
Silromen Avatar answered Oct 08 '22 18:10

Silromen