Write a Swift program to convert the last three characters in upper case


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. func casestr(_ input: String) -> String {
  2. if input.characters.count < 3
  3. {
  4. return input.lowercased()
  5. }
  6. else
  7. {
  8. var newInput = input.characters
  9. var str1: String = ""
  10. let lastThree = newInput.suffix(3)
  11. newInput.removeLast(3)
  12. let lastThreeUpper = String(lastThree).uppercased()
  13. str1.append(contentsOf: newInput)
  14. str1.append(String(lastThree).uppercased())
  15. return str1
  16. }
  17. }
  18.  
  19. print(casestr("TechStudy.org"))
  20. print(casestr("Swift"))

Result

swift programming languages techstudy.org

     





Related Topics





Popular Posts