How to calculate string length without spaces in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"strings"
)

func main() {
	str := "The Go Programming Language"
	
	// Remove all spaces from the string
	strWithoutSpaces := strings.ReplaceAll(str, " ", "")
	
	length := len(strWithoutSpaces)
	
	fmt.Println("Length without spaces:", length)
}



/*
run:

Length without spaces: 24

*/

 



answered Jan 11, 2025 by avibootz
...