Created
June 18, 2018 15:56
-
-
Save novinfard/035ff7f39a4b1d0d5815eab9e73f0a32 to your computer and use it in GitHub Desktop.
[Working with Strings]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var stringOne = "Hello llollo" | |
var stringTwo = "" | |
stringOne.isEmpty | |
stringTwo.isEmpty | |
stringOne == "Hello llollo" | |
stringOne == "hello" | |
stringOne.hasPrefix("He") | |
stringOne.hasSuffix("He") | |
stringOne.replacingOccurrences(of: "ll", with: "pp") | |
var path = "/one/two/three/four" | |
//Create start and end indexes | |
let startIndex = path.index(path.startIndex, offsetBy: 4) | |
let endIndex = path.index(path.startIndex, offsetBy: 14) | |
let sPath = path[startIndex..<endIndex] //returns the String /two/three | |
//convert the substring to a string | |
let newStr = String(sPath) | |
path.substring(to:startIndex) //returns the String /one | |
path[..<startIndex] // same in Swift 4 | |
path.substring(from:endIndex) //returns the String /four | |
path[endIndex...] // same in Swift 4 | |
path.last | |
path.first | |
//get the length of the string | |
var length = path.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment