-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathContents.swift
More file actions
77 lines (44 loc) · 2.05 KB
/
Copy pathContents.swift
File metadata and controls
77 lines (44 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//: Playground - noun: a place where people can play
import UIKit
// --- Multi-line string literal example ---
let multiLineString = """
Line One
Line Two
Line Three
"""
print("Multi-Line String: \(multiLineString)")
// --- Multi-line string literal with interpolation ---
var lineNumbers = [1, 2, 3]
let multiLineTemplate = """
Line: \(lineNumbers[0])
Line: \(lineNumbers[1])
Line: \(lineNumbers[2])
"""
print("\nMulti-Line String Template: \(multiLineTemplate)")
// --- Manipulating a multi-line string ---
// Creating Substring
var mutableMultiLineString = """
Hello AgnosticDev!
I really enjoy tutorials.
Especially Swift Tutorials!
"""
let startingIndex = mutableMultiLineString.index(mutableMultiLineString.startIndex, offsetBy: 19)
let endingIndex = mutableMultiLineString.index(mutableMultiLineString.startIndex, offsetBy: 44)
let range = startingIndex..<endingIndex
let substring = mutableMultiLineString.substring(with: range)
print("Second line: \(substring)")
// Replacing Values
let replacedString = mutableMultiLineString.replacingOccurrences(of: " ", with: "\n")
print("Replaced value string: \(replacedString)")
// --- String Equality ---
let nonEqualMultiLineString = """
Hello AgnosticDev!
I really enjoy tutorials. Especially Swift Tutorials!
"""
if mutableMultiLineString == nonEqualMultiLineString {
print("Multi-line strings are equal!")
} else {
print("No, these are not equal strings because of the missing newline, even though both strings have the same length.")
print("Length of mutableMultiLineString: \(mutableMultiLineString.characters.count)")
print("Length of nonEqualMultiLineString: \(nonEqualMultiLineString.characters.count)")
}