Skip to content

Instantly share code, notes, and snippets.

@manjeettahkur
Created November 30, 2018 07:06
Show Gist options
  • Save manjeettahkur/ff114ef92d8ffee1b797091ff77ea89f to your computer and use it in GitHub Desktop.
Save manjeettahkur/ff114ef92d8ffee1b797091ff77ea89f to your computer and use it in GitHub Desktop.
camelCase method in golang
/*
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,""))
}
@ForeverZer0
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment