Tech Study

Write a Swift program to move the last two characters of a given string to the start string

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 swapletters(_ str1: String) -> String {
    var chars = str1.characters
    let last_char = chars.removeLast()
    let rest_part = chars.removeLast()
    chars.insert(last_char, at: chars.startIndex)
    chars.insert(rest_part, at: chars.startIndex)
 
    return String(chars)
}
print(swapletters("tech"))
print(swapletters("study"))

Result

Write a Swift program to move the last two characters of a given string to the start string
Write a Swift program to move the last two characters of a given string to the start string

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