wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Strings in Swift

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which property of the string is used get number of characters?

a)

length

b)

length()

c)

count

d)

count()

2.

which method/methods is/are used to find the substrings in a given string?

a)

hasPrefix()

b)

contains()

c)

prefix(n)

d)

getChars(n)

3.

We can have an empty character

a)

True

b)

False

4.

let name = "Ethan Hunt"

print(name.first)

output is ?

a)

E

b)

Ethan

c)

optional(E)

d)

compiler error

5.

let pokemon = "poke\u{0301}mon"

print(Pokemon.count)

output is ?

a)

7

b)

8

c)

14

d)

none

6.

let kid = "Miles Morales"

print(kid[kid.index(kid.startIndex, offsetBy:3)]

output is ?

a)

e

b)

Optional(e)

c)

l

d)

optional(l)

7.

let scarlet = "Wanda Maximoff"

print(scarlet.substring(to:scarlet.firstIndex(of:" ")!)

output is :

a)

Wanda

b)

W

c)

Maximoff

d)

Compiler Error

8.

let strt1 = "liril"

let str2 = str1.reversed()

if str1 == str2 {

print("palindrome")

} else {

print("not a palindrome")

}

a)

not a palindrome

b)

palindrome

c)

compiler error

9.

What is the output of ?

let name = "TESSERACT"

print(name.min()!)

a)

optional(A)

b)

A

c)

tesseract

d)

compiler error

10.

let a = 10

let b = 20

let c = 30

let result = "Solve for c. 30 = \(a)x + \(b)"

output is ?

a)

Solve for 30. 30 = 10x + 20

b)

Solve for c. 30 = 10x + 20

c)

Solve for c. 30 = \1030 + 20

d)

error