← All languages
Go function of the day
Random

strconv.ParseBool

Parse a string to a boolean value.

Description

strconv.ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False as valid values.

Any other string value returns an error. This function is useful for parsing boolean flags from configuration files, environment variables, or user input.

strconv.ParseBool is strict in what it accepts, helping to avoid ambiguous boolean interpretations.

Arguments

NameDescriptionOptional
str The string to parse. No

Example

b, err := strconv.ParseBool("true")
if err != nil {
    log.Fatal(err)
}
fmt.Println(b)  // true

Reference