Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusing ToUpper and ToTitle

Tags:

unicode

go

Is there any difference between the ToUpper and the ToTitle function?

like image 216
jasonz Avatar asked Sep 01 '13 14:09

jasonz


People also ask

Why would it be useful to include the ToUpper method in a comparison?

The ToUpper method is often used to convert a string to uppercase so that it can be used in a case-insensitive comparison. A better method to perform case-insensitive comparison is to call a string comparison method that has a StringComparison parameter whose value you set to StringComparison.

Does ToUpper work on strings?

C++ String has got built-in toupper() function to convert the input String to Uppercase.

What is ToUpper in Visual Basic?

ToUpper converts all characters to uppercase characters. It causes a copy to be made of the VB.NET String, which is returned. Here We look at ToUpper and its behavior. This console program shows the result of ToUpper on the input String "abc123".

How do you use string ToUpper?

String. This method is used to returns a copy of the current string converted to uppercase. Syntax: public string ToUpper(); Return Type: Its return the string value, which is the uppercase equivalent of the given string.


2 Answers

See this example on the difference of titlecase/uppercase:

package main

import (
    "fmt"
    "strings"
)

func main() {
    str := "dz"
    fmt.Println(strings.ToTitle(str))
    fmt.Println(strings.ToUpper(str))
}

(Note "dz" here is a single character, not a "d" followed by a "z": dz vs dz)

http://play.golang.org/p/xpDPLqKM9C

like image 197
topskip Avatar answered Oct 12 '22 02:10

topskip


I had the same problem. You want to use the strings.Title() method not the strings.ToTitle() method.

http://golang.org/pkg/strings/#Title

like image 38
Brenden Avatar answered Oct 12 '22 03:10

Brenden