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 ...
随机推荐
- VS2012旗舰版接选择调试 出现了这样一个错误
问题: 解决: 项目-右键-属性,勾选如下配置试试
- RMQ模板
RMQ:范围最小值问题.给出一个n个元素的数组A1,A2,...,An,设计一个数据结构支持查询操作Query(L,R):计算min{AL,AL+1,...,AR}. 每次用一个循环来求最小值显然不够 ...
- Raspberry Pi 3 --- Kernel Building and Run in A New Version Kernal
ABSTRACT There are two main methods for building the kernel. You can build locally on a Raspberry Pi ...
- Python字典和集合
Python字典操作与遍历: 1.http://www.cnblogs.com/rubylouvre/archive/2011/06/19/2084739.html 2.http://5iqiong. ...
- magelinux notes
[root@centos01 01]# cd ~jack #进入指定用户的家目录[root@centos01 jack]# cd - #切回上一次目录[root@centos01 home]# cd ...
- easyUI draggable插件使用不当,导致拖动div内部文本框无法输入;设置echarts数据为空时就显示空白,不要动画和文字
先上一个Demo <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww ...
- <摘录>如何在64位linux强制编译32位应用程序
GDC注:因为需要解决在linux64机上编译32位的mongodb(没办法,因为编译的php是32位,然后我想将mongdb扩展添加到php中),在网上搜了很多文章,感觉这篇好懂,而且好用.我使用的 ...
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【二】——使用Repository模式构建数据库访问层
系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 前言 在数据访问层应用Repository模式来隔离对领域对象的细节操作是很有意义的.它位于映射层 ...
- Mac 使用Sublime Text 3搭建java环境
运行效果 运行的时候会在桌面上生成一个 .class文件,可以通过配置文件将生成的.class文件删除. 参考: java环境配置:http://developer.51cto.com/art/201 ...
- winform的扩展的带有截图功能picturebox
using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using Sys ...