typestar

The strings package in Go

Trimming, splitting, joining, and building text.

func textOps(input string) (string, int, []string) {
    trimmed := strings.TrimSpace(input)
    upper := strings.ToUpper(trimmed)
    count := strings.Count(trimmed, "o")
    parts := strings.Split(trimmed, " ")

    var b strings.Builder
    for _, part := range parts {
        b.WriteString(strings.Title(part))
    }
    joined := strings.Join(parts, "-")
    _ = upper
    return joined + b.String(), count, parts
}

How it works

  1. TrimSpace, ToUpper, and Count inspect text.
  2. Split and Join convert to and from slices.
  3. strings.Builder concatenates efficiently.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
373
Tokens
103
Three-star pace
95 tpm

At the three-star pace of 95 tokens a minute, this run takes about 65 seconds.

Type this snippet

Step 1 of 5 in Strings & formatting, step 25 of 30 in Language basics.

← Previous Next →