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...
int len = [myString length];
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.
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.
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];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With