Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb5c991

Browse files
ended up with strings
1 parent 21111d0 commit fb5c991

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

‎SwiftBasics/Strings.playground/Contents.swift

100755100644
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ var jamesFavoriteBaseballTeam = "Atlanta Braves"
1717

1818
var nWithTilde = "\u{006E}\u{0303}"
1919
nWithTilde.unicodeScalars.count
20-
nWithTilde.characters.count
20+
nWithTilde.count
2121

2222
//: ## Emoji characters
23-
let similarTruth = "💰can't buy me 💖"
23+
let similarTruth = "💰 🍞 can't buy me 💖"
2424

2525
// Here's one way to initialize an empty Swift string
26-
var characterPoorString = ""
26+
var characterPoorString = "abcdef"
2727

2828
// And here's another
2929
let potentialRichString = String()
30-
characterPoorString.characters
30+
characterPoorString.count
3131

3232
//: ## String interpolation
3333

@@ -50,6 +50,9 @@ dogName = "Lil Frankie"
5050
doggyDiet = "\(dogName) eats ?lbs of dog food per month"
5151
//: ## A String isn't just a String
5252

53+
var myName = "divyanshu"
54+
print("my name is \(myName)")
55+
5356
//: ### Through the .characters property we can access an array of characters
5457
var password = "Meet me in St. Louis"
5558
for character in password.characters {
@@ -59,6 +62,17 @@ for character in password.characters {
5962
}
6063
}
6164

65+
for char in myName.characters{
66+
if char == "a"{
67+
print("got it")
68+
}
69+
else{
70+
71+
}
72+
}
73+
6274
//: ### A String can be treated as an NSString
6375
let newPassword = password.replacingOccurrences(of: "e", with: "3")
6476

77+
let modifiedName = myName.replacingOccurrences(of: "d", with: "4")
78+

‎SwiftBasics/Strings.playground/contents.xcplayground

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='5.0' target-platform='ios' display-mode='rendered'>
2+
<playground version='5.0' target-platform='ios' display-mode='raw'>
33
<timeline fileName='timeline.xctimeline'/>
44
</playground>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /