9.25. Swift character

发布时间 : 2025-10-25 13:33:48 UTC      

Page Views: 10 views

The character of Swift is a single character string literal, and the data type is Character .

The following example lists two character instances:

import Cocoa let char1: Character = "A" let char2: Character = "B" print("The value of char1 is \(char1)") print("The value of char2 is \(char2)") 

The output of the above program execution is as follows:

The value of char1 is A The value of char2 is B 

If you want to Character if more characters are stored in the constant of type (character), the program execution will report an error, as shown below:

import Cocoa // The following assignments in Swift will result in an error message let char: Character = "AB" print("Value of char \(char)") 

The output of the above program execution is as follows:

error: cannot convert value of type 'String' to specified type 'Character' let char: Character = "AB" 

9.25.1. Null character variable #

Cannot create empty in Swift Character type variable or constant:

import Cocoa // The following assignments in Swift will result in an error message let char1: Character = "" var char2: Character = "" print("The value of char1 \(char1)") print("The value of char2 \(char2)") 

The output of the above program execution is as follows:

 error: cannot convert value of type 'String' to specified type 'Character' let char1: Character = "" ^~ error: cannot convert value of type 'String' to specified type 'Character' var char2: Character = "" 

9.25.2. Traverse characters in a string #

Swift’s String type represents a specific sequence Character a collection of type values. Each character value represents a Unicode characters.

In Swift 3 String need to pass through characters the property method to be called, which is available in Swift 4 through the String the object itself is called directly, for example:

In Swift 3:

import Cocoa for ch in "Runoob".characters { print(ch) } 

In Swift 4:

import Cocoa for ch in "Runoob" { print(ch) } 

The output of the above program execution is as follows:

R u n o o b 

9.25.3. String concatenation character #

The following example demonstrates the use of the String of append() method to implement string concatenation characters:

import Cocoa var varA:String = "Hello " let varB:Character = "G" varA.append( varB ) print("varC = \(varA)") 

The output of the above program execution is as follows:

varC = Hello G 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。