Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Has Prefix in Go

HasPrefix function is used to check if a mainString starts with a particular substring.

What is a prefix ?
If a string starts with a given term, it is called as prefix. For example in iphone, ip is a prefix and iph is also a prefix. But in is not a prefix.

package main

import (
    "fmt"
    "strings"
)

func main() {

    mainString := "iPhone"

    // starts with
    hasPrefix := strings.HasPrefix(mainString, "I")
    fmt.Printf("%v\n", hasPrefix)

    hasPrefix = strings.HasPrefix(mainString, "i")
    fmt.Printf("%v\n", hasPrefix)
}