Write a Swift program to test if a given string starts with "test"


Introduction

I have used Swift for windows 1.9 for debugging purpose. But you can use any Swift programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1.  
  2. import Foundation
  3.  
  4. func checkstring(_ input: String) -> Bool {
  5. if input.hasPrefix("test")
  6. {
  7. return true
  8. }
  9. else
  10. {
  11. return false
  12. }
  13. }
  14. print(checkstring("testpqrsab"))
  15. print(checkstring("testabpqrsab"))
  16. print(checkstring("pqrs"))
  17. print(checkstring("abpqrs"))

Result

swift programming languages techstudy.org

     





Related Topics





Popular Posts