GopherSnippetsStar

Code snippets with tests and testable examples for the Go programming language

How to check if a string starts with substring

Snippets Index - Run code on Go playground - Edit

package main

import (
	"fmt"
	"strings"
)

func Example() {
	fmt.Println(strings.HasPrefix("abcdefg", "ab"))
	fmt.Println(strings.HasPrefix("abcdefg", "Ab"))
	// Output:
	// true
	// false
}

by psampaz - source code - comment below or here