Tech Study

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.

func casestr(_ input: String) -> String {
    if input.characters.count < 3
    {
        return input.lowercased()
    } 
    else
    {
        var newInput = input.characters
        var str1: String = ""
        let lastThree = newInput.suffix(3)
        newInput.removeLast(3)
        let lastThreeUpper = String(lastThree).uppercased()
        str1.append(contentsOf: newInput)
        str1.append(String(lastThree).uppercased())
        return str1
    }
}
 
print(casestr("TechStudy.org")) 
print(casestr("Swift"))

Result

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

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

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more