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

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more