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

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

Function Pointer in C++

Introduction : Function Pointer in C++ Pointers: In function pointer in c++ are the variables that consist of addresses of …

Read more