字符串前@符号的用途? [英] Purpose of @ Symbol Before Strings?

查看:78
本文介绍了字符串前@符号的用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Objective-C一段时间,但从来没有真正理解所有字符串之前@符号的用途是什么。例如,为什么你必须声明这样的字符串:

I've been using Objective-C for a while now, but have never really understood what the purpose of the @ symbol before all strings is. For instance, why do you have to declare a string like this:

NSString *string = @"This is a string";

而不是这样:

NSString *anotherString = "This is another string";

就像在Java或许多其他编程语言中一样。有充分的理由吗?

as you do in Java or so many other programming languages. Is there a good reason?

推荐答案

它表示NSString(而非标准C字符串)

It denotes a NSString (rather than a standard C string)

NSString是一个存储unicode字符串的Object,它提供了一堆方法来帮助操作。

an NSString is an Object that stores a unicode string and provides a bunch of method to assist with manipulating.

一个C字符串只是一个\0终止一堆字符(字节)。

a C string is just a \0 terminated bunch of characters (bytes).

编辑:好的原因是Objective-C构建在C之上,C语言结构需要是仍然可用。 @是仅限目标c的扩展名。

and the good reason is that Objective-C builds on top of C, the C language constructs need to be still available. @"" is an objective-c only extension.

这篇关于字符串前@符号的用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆