Tech Study

Write a Swift program to test if a given string starts with “test”

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.

import Foundation
 
func checkstring(_ input: String) -> Bool {
    if input.hasPrefix("test")
    {
        return true
    } 
    else 
    {
        return false
    }
}
print(checkstring("testpqrsab"))
print(checkstring("testabpqrsab"))
print(checkstring("pqrs"))
print(checkstring("abpqrs"))

Result

Write a Swift program to test if a given string starts with "test"
Write a Swift program to test if a given string starts with “test”

TaggedWrite a Swift program to test if a given string starts with "test"

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