Parse a string to a boolean value.
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.
| Name | Description | Optional |
|---|---|---|
str |
The string to parse. | No |
b, err := strconv.ParseBool("true")
if err != nil {
log.Fatal(err)
}
fmt.Println(b) // true