Created
November 30, 2018 07:06
-
-
Save manjeettahkur/ff114ef92d8ffee1b797091ff77ea89f to your computer and use it in GitHub Desktop.
camelCase method in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Title: | |
Break camelCase | |
Description: | |
Write simple .camelCase method (camel_case function in PHP or CamelCase in C#) for strings. All words must have their first letter capitalized without spaces. | |
Examples: | |
"hello case".camelCase() => HelloCase | |
"camel case word".camelCase() => CamelCaseWord | |
Kata Link: | |
https://www.codewars.com/kata/break-camelcase | |
Discuss Link: | |
https://www.codewars.com/kata/break-camelcase/discuss | |
Solutions Link: | |
https://www.codewars.com/kata/break-camelcase/solutions | |
*/ | |
package main | |
import ( | |
"strings" | |
"fmt" | |
) | |
func main(){ | |
var s string = "user name" | |
var g []string | |
p := strings.Fields(s) | |
for _,value := range p { | |
g = append(g,strings.Title(value)) | |
} | |
fmt.Println(strings.Join(g,"")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is conversion to Pascal case, not camel.
PascalCaseString
is each word capitalized, including the first word (i.e. C#).camelCaseString
is each word capitalized, excluding the first word, which is always lowercase (i.e. Java).