Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to separate word in string by first capital letter of each word in Go

1 Answer

0 votes
package main
 
import (
    "fmt"
    "regexp"
)
 
func spaceString(s string) string {
    var matchAllCapitals = regexp.MustCompile("([a-z0-9])([A-Z])")
    s = matchAllCapitals.ReplaceAllString(s, "${1} ${2}")
    
    return s
}
 
func main() {
    fmt.Println(spaceString("GoJavaPython"))
    fmt.Println(spaceString("GoJavaPythonPHP"))
    fmt.Println(spaceString("Go12Java43Python6PHP54"))
    fmt.Println(spaceString("PHPGoJavaPython"))
}




/*
run:

Go Java Python
Go Java Python PHP
Go12 Java43 Python6 PHP54
PHPGo Java Python

*/

 



answered Aug 26, 2020 by avibootz
edited Aug 26, 2020 by avibootz
...