how to find string length using strlen in objective c

后端 未结 3 725
花落未央
花落未央 2021-02-02 08:02

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条回答
  • 2021-02-02 08:17

    Use length method, like this:

    NSString *myString = @"Hello World";
    int myLength = [myString length]; //myLength is now 11
    
    0 讨论(0)
  • 2021-02-02 08:20

    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 讨论(0)
  • 2021-02-02 08:29

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

    0 讨论(0)
提交回复
热议问题