Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. var str = "Hello, Agnostic Dev"
  2. var charArr: [Character] = ["A", "g", "n", "o", "s", "t", "i", "c"]
  3.  
  4. // Берет 2 первые буквы
  5. if str.prefix(2) == "He" {
  6. print("I found \(str.prefix(2))") // находит He
  7. }
  8.  
  9. // Берет последние 3 буквы
  10. if str.suffix(3) == "Dev" {
  11. print("I found \(str.suffix(3))") // Находит dev
  12. }
  13.  
  14. // First three from charArr: ["A", "g", "n"]
  15. print("First three from charArr: \(charArr.prefix(3))")
  16.  
  17. // Last three from charArr: ["t", "i", "c"]
  18. print("Last three from charArr: \(charArr.suffix(3))")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement