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 ...
随机推荐
- C# 生成xml文件
本篇文章旨在.net环境下生成xml文件,以控制台应用程序为例进行说明. 1.在vs中新建控制台应用程序CreateXml 2.CreateXmlFile:主要生成xml的函数 public void ...
- HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))
传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...
- Django REST framework简单使用
详细的见 https://github.com/linux-wang/DRF_tutorial/blob/master/README.md DRF中有一个serializer的概念,实现的功能是将各种 ...
- Code笔记之:CSS+HTML display 属性
display属性值:none 此元素不会被显示. block 此元素将显示为块级元素,此元素前后会带有换行符. inline 默认.此元素会被显示为内联元素,元素前后没有换行符. inline-bl ...
- 启动和关闭ADB服务(adb start-server和adb kill-server)
1 Android SDK中的常用命令行工具 在<Android SDK安装目录>\tools目录中带了很多命令行工具.虽然一般的开发人员并不需要完全掌握这些工具的使用方法,但了解这些工 ...
- 【Alpha阶段】第三次Scrum例会
会议信息 时间:2016.10.19 21:00 时长:0.5h 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 个人任务报告 姓名 今日已完成Issue 明日计划Issue 今日已做事务 工 ...
- linux下git的简单运用
linux下git的简单运用 windows下也有git,是git公司出的bash,基本上模拟了linux下命令行.许多常用的命令和linux下操作一样.也就是说,windows下的git命令操作和l ...
- BZOJ1031: [JSOI2007]字符加密Cipher
传送门 后缀数组模板题 //BZOJ 1031 //by Cydiater //2016.9.21 #include <iostream> #include <cstring> ...
- 通过System.getProperties()获取系统参数
Properties props=System.getProperties(); //系统属性 System.out.println("Java的运行环境版本:"+props ...
- css3之2D转换
css3---2D转换 css3中出现了许多新的特性,其中2D转换我觉的非常有意思,通过她,我们能够对元素进行移动.缩放.转动.拉长或者拉伸,所以希望在这里和大家分享一下. 这里,我将会介绍到以下转换 ...