The following function does not work with Swedish characters, i.e å/Å/ä/Ä/ö/Ö
.
func StartsWithUppercase(s string) bool {
return (string(s[0]) == strings.ToUpper(string(s[0])))
}
How do I proceed to check if a string starts with upper case Swedish character?
w := "åÅäÄöÖ"
for i := 0; i < len(w); i++ {
fmt.Println(i, w[i])
}
Results in:
1. 195
2. 165
3. 195
4. 133
5. 195
6. 164
7. 195
8. 132
9. 195
10. 182
11. 195
12. 150
This page allows you to easily type Swedish characters without a Swedish keyboard. You can edit your text in the box and then copy it to your document, e-mail message, etc. Still copying & pasting your Swedish characters? Get the TypeIt App for PC to type Swedish characters directly into your documents and messages.
Swedish ( svenska [²svɛnːska] (listen)) is a North Germanic language spoken natively by 10 million people, predominantly in Sweden (as the sole official language), and in parts of Finland, where it has equal legal standing with Finnish. It is largely mutually intelligible with Norwegian and to some extent with Danish,...
Grammar. As Swedish is a Germanic language, the syntax shows similarities to both English and German. Like English, Swedish has a subject–verb–object basic word order, but like German it utilizes verb-second word order in main clauses, for instance after adverbs and adverbial phrases, and dependent clauses.
Swedish has all the letters of the English alphabet plus three extra ones, they are the letters Å, Ä, and Ö. These three letters are considered as separate letters and not letters with diacritical marks. They come in alphabetical order after the letter Z. There are multiple ways to type these letters Å, Ä, and Ö into a program.
Indexing a string
indexes its bytes not its runes (a rune
is a unicode codepoint).
What you want to do is check the first character (rune
) of the string
, not its first byte in its UTF-8 encoded form. And for this there is support in the standard library: unicode.IsUpper()
.
To get the first rune
, you can convert the string
to a slice of runes, and take the first element (at index 0).
ins := []string{
"å/Å/ä/Ä/ö/Ö",
"Å/ä/Ä/ö/Ö"}
for _, s := range ins {
fmt.Println(s, unicode.IsUpper([]rune(s)[0]))
}
Output:
å/Å/ä/Ä/ö/Ö false
Å/ä/Ä/ö/Ö true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With