How to return a string from a function in Swift

2 Answers

0 votes
func removeFirst3Chars(value: String) -> String {
    return String(value[value.index(value.startIndex, offsetBy: 3)..<value.endIndex])
}

print(removeFirst3Chars(value: "swift"))
  
  
  
   
/*
run:
 
ft
   
*/

 



answered Nov 10, 2020 by avibootz
0 votes
func f() -> String {
    return String("swift")
}

print(f())
  
  
  
   
/*
run:
 
swift
   
*/

 



answered Nov 10, 2020 by avibootz
...