println("Value of char1 \(char1)")
println("Value of char2 \(char2)")Accessing Characters from Strings
As explained while discussing Swift's Strings, String represents a collection of Character
values in a specified order. So we can access individual characters from the given String
by iterating over that string with a for-in loop:
import Cocoafor ch in "Hello" {
println(ch)
}When the above code is compiled and executed, it produces the following result:
H
e
l
l
oConcatenating Strings with Characters
The following example demonstrates how a Swift's Character can be concatenated with
Swift's String.
import Cocoavar varA:String = "Hello "
let varB:Character = "G"varA.append( varB )println("Value of varC = \(varA)")When the above code is compiled and executed, it produces the following result:
Value of varC Hello G