Hi!
What is the easiest way to make a string "LikeThis" --> "likeThis"?
--
--
import "unicode"
func UpcaseInitial(str string) string {
for i, v := range str {
return string(unicode.ToUpper(v)) + str[i+1:]
}
return ""
import "unicode"
func LowerInitial(str string) string {
for i, v := range str {
return string(unicode.ToLower(v)) + str[i+1:]
--
Sorry, thought that was clear: Why is appending the remainder of the string to the modified first rune more efficient that converting to a []rune and then converting back the modified slice.
ujjwalt's explanation that, in your example, only the first rune needed to be decoded and the remainder can then be appended without decoding makes sense.
Hi!What is the easiest way to make a string "LikeThis" --> "likeThis"?
bytestr := []byte(str)
for index, character := range bytestr {
char := string(character)
if char == strings.ToUpper(char) {
// Is lowercase
bytestr[index] = []byte(strings.ToLower(char))[0]
} else {
bytestr[index] = []byte(strings.ToUpper(char))[0]
}
}
What if the first character is a combined code point?
John
John Souvestre - New Orleans LA
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Yes, I initially started the string with “A\u0312a”. The combining code point appears over the second “a” rather than the first. Hence my question.
But after thinking about it and doing some additional testing, this appears to be a problem with my setup (Chrome on Windows 7). For example, when I use “A\u0313a” instead, it works as expected.
I tried about a dozen different combining points, and I found the same problem for 2 others (\u0321 and \u0322), but all the rest are OK.
Very strange. J
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/WfpmVDQFecU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
package main
import (
"fmt"
"strings"
)
func ToLowerCase(str string) string {
var b strings.Builder
b.WriteString(strings.ToLower(string(str[0])))
b.WriteString(str[1:])
return b.String()
}
func main() {
var str string = "GoLang"
fmt.Println(ToLowerCase(str))
}
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/59ede7f8-bfb9-44a0-9fa7-cef1d7288983o%40googlegroups.com.