Swift3.0P1 语法指南——字符串与字符
1、字符串字面值
let someString = "Some string literal value"
2、初始化空的字符串
两种方法:
var emptyString = "" // empty string literal
var anotherEmptyString = String() // initializer syntax
// these two strings are both empty, and are equivalent to each other
可以通过isEmpty属性检查字符串是否为空:
if emptyString.isEmpty {
print("Nothing to see here")
}
// prints "Nothing to see here"
3、字符串的可变性
通过声明为常量或变量来判断字符串是否可变。
var variableString = "Horse"
variableString += " and carriage"
// variableString is now "Horse and carriage" let constantString = "Highlander"
constantString += " and another Highlander"
// this reports a compile-time error - a constant string cannot be modified
这种方式与Objective-C不同。Objective-C需要用NSString和NSMutableString两种类来分别表示不可变字符串和可变字符串。
4、字符串是值类型
Swift 的 String 类型是值类型。如果你创建了一个新的字符串值,那么当其进行常量、变量赋值操作或在函数中传递时,会进行值拷贝。在不同情况下,都会对已有字符串值创建新副本,并对该新副本进行传递或赋值。
5、使用字符
for character in "Dog!Swift3.0P1 语法指南——字符串与字符的更多相关文章
- Swift3.0P1 语法指南——枚举
原档: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programm ...
- Swift3.0P1 语法指南——闭包
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Swift3.0P1 语法指南——构造器
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Swift3.0P1 语法指南——属性
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Swift3.0P1 语法指南——类和结构体
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Swift3.0P1 语法指南——基本操作符
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Swift3.0P1 语法指南——下标
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Swift3.0P1 语法指南——方法
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
- Swift3.0P1 语法指南——函数
原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...
随机推荐
- vi编辑文件出现Can't open file for writing错误
可以用 ll 命令查看一下文件的权限,很有可能是没有权限,用chmod命令修改一下权限就可以了(当然是文件所有者或者root用户才能修改),或者切换成root用户(不推荐)
- 个人作业—Week3
博客阅读体会 阅读了十几位软件工程师前辈的博文,了解了前辈们作为一名软件工程师的成长经历,我有一些感触. 这十几位前辈们的经历有着很大的差别,有的科班出身,有的则完全自学成才.不同的经历使得前辈们看问 ...
- primefaces p:dataExporter filename 支持中文 utf8
p:fileDownload and p:dataExporter : for p:fileDownload, the Content-Disposition header should be set ...
- JavaWeb---总结(十六)JSP指令
一.JSP指令简介 JSP指令(directive)是为JSP引擎而设计的,它们并不直接产生任何可见输出,而只是告诉引擎如何处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指令: pa ...
- cobbler深入学习
cobbler重要目录和cobbler各对象的关系 /var/www/cobbler/ks_mirror 存放操作系统镜像/var/www/cobbler/repo_mirror 存放仓库镜像/var ...
- linux程序处理po多语言的两种脚本配置方式
1.在configure.ac里面配置ALL_LINGUAS,然后调用AM_GLIB_GNU_GETTEXT 2.在po目录下面放置LINGUAS文件,由gettextize来生成并处理
- Module模式
<script> var myModel=(function(){ var model={}; var privateVar="Hello World"; functi ...
- 日志分析 第一章 ELK介绍
1 ELK各组件介绍? ELK Stack是elasticsearch.logstash.kibana是三个开源软件的组合, fielbeat是一个轻量级日志收集工具,类似于Linux系统中tail ...
- centos nc命令安装
yum install nc.x86_64 nc命令的参数 参数 作用-i 设置数据报传送时间间隔-l 以服务器方式运行-k 重复接收并处理某个端口上的所有连接,必须与-l选项一起使用-n 使用ip地 ...
- linux手动或者自动启动oracle11g的服务 Oracle 自动启动脚本
手动启动: [oracle@localhost ~]$ sqlplus SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 26 23:39:52 2 ...