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"

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