string 如何在目标c中使用strlen查找字符串长度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3846064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:52:07  来源:igfitidea点击:

how to find string length using strlen in objective c

iphonexcodestring

提问by Linux world

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

我在 str 变量中存储了一个字符串,我想找到 str 变量中可用的字符串长度

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

我试过 strlen(str); 它不工作...

回答by vodkhang

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

如果您的字符串是 C-String,那么您可以使用strlen(str).

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

如果是 a NSString *str,那么你可以使用NSUInteger length = [str length];

回答by Silromen

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

你的字符串是什么类型的?如果它是一个 NSString,你会找到这样的长度:

int len = [myString length];

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

但如果您的字符串不是 NSString,则情况会有所不同。

回答by Cokegod

Use length method, like this:

使用长度方法,如下所示:

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