How to count the number of characters in a string without spaces and special characters in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"regexp"
)

func main() {
	str := "8go c# rust, java: 123 c &c++."

	re := regexp.MustCompile("[^A-Za-z]")

	result := len(re.ReplaceAllString(str, ""))

	fmt.Println(result)
}


/*
run:

13

*/

 



answered Sep 16, 2024 by avibootz
...