new task
This commit is contained in:
+23
-13
@@ -1,27 +1,37 @@
|
||||
package main
|
||||
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
func ToCamelCase(s string) string {
|
||||
// your code
|
||||
dash := "-"
|
||||
// und := "_"
|
||||
if strings.Contains(s,dash) {
|
||||
fmt.Println("Contains dashes!")
|
||||
index := strings.Index(s,dash)
|
||||
fmt.Println(index)
|
||||
fmt.Println(strings.ReplaceAll(s,string(s[index:index]),strings.ToUpper(string(s[index+1]))))
|
||||
var fin string
|
||||
fin = s
|
||||
symbs := []string{"-","_"}
|
||||
for _, ind := range symbs {
|
||||
if strings.Contains(s,ind) {
|
||||
|
||||
index := strings.Index(s,ind)
|
||||
|
||||
initStr := s
|
||||
substr := initStr[index:index+2]
|
||||
toRepl := strings.ToUpper(string(initStr[index+1]))
|
||||
|
||||
fin = strings.Replace(s,substr,toRepl,1)
|
||||
|
||||
fin = ToCamelCase(fin)
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return fin
|
||||
}
|
||||
|
||||
func main() {
|
||||
ToCamelCase("the-stealth-warrior")
|
||||
// ToCamelCase("The_Stealth_Warrior")
|
||||
// ToCamelCase("The_Stealth-Warrior")
|
||||
fmt.Println(ToCamelCase("the-stealth-warrior"))
|
||||
fmt.Println(ToCamelCase("The_Stealth_Warrior"))
|
||||
fmt.Println(ToCamelCase("The_Stealth-Warrior"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user