You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Hamza elkhatri 292e9b8bae Update README.md 2 years ago
..
README.md Update README.md 2 years ago

README.md

Camel-to-snake-case

Instructions

Write a function that converts a string from a camel case to a snake case.

  • If the string is empty, return an empty string.
  • If the string is not a camel case, return the string unchanged.
  • If the string is a camel case, return the snake case version of the string.
  • Camel case is the practice of writing phrases without spaces or punctuation, It indicates the separation of words with a single capitalized letter
  • Snake case is a style of writing in which each space is replaced by an underscore (_) character.

Expected function

func CamelToSnakeCase(s string) string{
    //Your code here
}

Usage

package main

import "fmt"

func main() {
    fmt.Println(CamelToSnakeCase("HelloWorld")) 
    fmt.Println(CamelToSnakeCase("heloWorld"))
    fmt.Println(CamelToSnakeCase("CamelToSnakeCase"))
    fmt.Println(CamelToSnakeCase("132322"))
    fmt.Println(CamelToSnakeCase(""))
}

and the output should be:

$ go run . | cat -e
Hello_World$
helo_World$
Camel_To_Snake_Case$
132322$
$