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

Related questions

1 answer 219 views
1 answer 107 views
1 answer 102 views
1 answer 110 views
1 answer 103 views
...