OC開発-NSString(21)

概要

C言語の文字列型はchar、OCの文字列はNSString、文字列の識別子は "@"で始まり、その後に二重引用符が続きます。二重引用符は文字列の内容です

2つのNSStringコード例

#include <Foundation/Foundation.h>

int main()
{
    NSString *str=@"hello";
    char *str2="hello";

    NSLog(@"OC语言字符串:%@",str);
    NSLog(@"C语言字符串:%s",str2);
    int age=15;
    int no=5;
    NSString *name=@"jack";
    int size=[name length];
    NSString *newStr=[NSString stringWithFormat:@"My age is %d and no is %d and name=%@",age,no,name];
    NSLog(@"%@",newStr);
    NSLog(@"name的长度是%d",size);
    return 0;
}
362の元の記事を公開 118の賞賛 530,000ビュー

おすすめ

転載: blog.csdn.net/Calvin_zhou/article/details/105317220