當前位置: 首頁>>代碼示例>>Golang>>正文


Golang strings.ToTitle函數代碼示例

本文整理匯總了Golang中strings.ToTitle函數的典型用法代碼示例。如果您正苦於以下問題:Golang ToTitle函數的具體用法?Golang ToTitle怎麽用?Golang ToTitle使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ToTitle函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetNpcs

func GetNpcs() (npcs []*Npc) {
	var data []NpcInfo
	err := utils.LoadSetting(&data, "data/npc.json")
	if err != nil {
		panic(err.Error())
	}

	for _, npcType := range data {
		for _, location := range npcType.Locations {
			for locName, count := range location {
				counter := 0
				npcClass := npcType.Class
				npcBehavior := npcType.Behavior
				for i := 0; i < count; i++ {
					counter++
					npc := &Npc{
						Character{
							Name:            fmt.Sprintf("%s#%d", strings.ToTitle(npcBehavior), counter),
							Class:           npcClass,
							CurrentLocation: locName,
							OwnerUid:        fmt.Sprintf("%s#%d", strings.ToTitle(npcBehavior), counter),
						},
						ai.Behavior(npcBehavior),
					}
					npc.SetDefaults()
					npcs = append(npcs, npc)

				}
			}

		}
	}

	return
}
開發者ID:sintell,項目名稱:TheTower,代碼行數:35,代碼來源:npc.go

示例2: ExampleToTitle

func ExampleToTitle() {
	fmt.Println(strings.ToTitle("loud noises"))
	fmt.Println(strings.ToTitle("хлеб"))
	// Output:
	// LOUD NOISES
	// ХЛЕБ
}
開發者ID:kheyalimitra,項目名稱:GeNA-Miner-Site,代碼行數:7,代碼來源:main.go

示例3: main

func main() {
	fmt.Println(strings.Index("chicken", "ken"))
	fmt.Println(strings.Index("chicken", "dmr"))

	fmt.Println(strings.ContainsAny("team", "e"))
	fmt.Println(strings.ContainsAny("failure", "u & i"))
	fmt.Println(strings.ContainsAny("foo", ""))
	fmt.Println(strings.ContainsAny("", ""))

	fmt.Println(1 & 1)
	fmt.Println(2 & 1)
	fmt.Println(4 & 1)
	fmt.Println(5 & 1)

	pow, sq := HashTest("1234567")
	fmt.Println(pow)
	fmt.Println(sq)

	str := "df 世 界 asd"
	s := "1界"
	index := strings.IndexAny(str, "界")
	fmt.Printf("%d......\n", index)
	for i, c := range str {
		fmt.Println(i)
		for _, m := range s {
			fmt.Printf("%c\t%c\n", c, m)
		}
	}

	for i := len(str); i > 0; {
		rune, size := utf8.DecodeLastRuneInString(str[0:i])
		fmt.Printf("%v\t", i)
		i -= size
		for _, m := range s {
			fmt.Printf("%c\t%v\t%v\n", rune, size, m)
		}
	}

	fmt.Println("bytes =", len(str))
	fmt.Println("runes =", utf8.RuneCountInString(str))

	for _, ss := range strings.Fields(str) {
		fmt.Println(ss)

	}
	fmt.Println(strings.ToTitle(str))

	str = "Hello, 世界"

	// for len(str) > 0 {
	// 	r, size := utf8.DecodeRuneInString(str)
	// 	fmt.Printf("%c %v\n", r, size)

	// 	str = str[size:]
	// }
	fmt.Println(Replace(str, "", "f", -1))

	hulu := new(huluwa)
	hello(hulu)
}
開發者ID:suifengRock,項目名稱:go-source,代碼行數:60,代碼來源:main.go

示例4: Render

// Renders a set of data provided by the module into the format specified by the request. Normally, this means that the data is rendered into HTML (mobile vs. desktop is automatically selected), but we may add support for ?alt=json or such at a later point
func Render(c http.ResponseWriter, r *http.Request, title, name string, data interface{}) {
	if WouldUseJson(r) {
		enc := json.NewEncoder(c)
		err := enc.Encode(data)
		if err != nil {
			Error500(c, r, err)
		}
		return
	}
	var p PageInfo
	if title == "" {
		title = strings.ToTitle(moduleName)
	}
	// 	if moduleName == "unknown" {
	// 		log.Println("Warning: Attempting to render a template without moduleName being set! Call SetModuleName during the initialization of your module in order to correct this (in main()).")
	// 	}
	p.Title = title
	// Removed the modulename because it's not needed in the new framework. However, this will break things in the old framework. *sigh*...
	p.Name = /*moduleName + "/" + */ name
	p.Request = r
	perms, err := perms.Get(r)
	if err != nil {
		log.Printf("Warning: Error getting page permissions for %s: %s", r.URL, err)
	}
	p.Perms = perms
	p.Object = data

	err = Execute(c, &p)
	if err != nil {
		c.WriteHeader(500)
		fmt.Fprintln(c, "FATAL ERROR:", err)
		return
	}
}
開發者ID:WalterShe,項目名稱:wfdr,代碼行數:35,代碼來源:template.go

示例5: MuckRequest

func (m *HttpTampererSymptom) MuckRequest(ctx *muxy.Context) {

	// Body
	if m.Request.Body != "" {
		newreq, err := http.NewRequest(ctx.Request.Method, ctx.Request.URL.String(), bytes.NewBuffer([]byte(m.Request.Body)))
		if err != nil {
			log.Error(err.Error())
		}
		*ctx.Request = *newreq
		log.Debug("Spoofing HTTP Request Body with %s", log.Colorize(log.BLUE, m.Request.Body))
	}

	// Set Cookies
	for _, c := range m.Request.Cookies {
		c.Expires = stringToDate(c.RawExpires)
		log.Debug("Spoofing Request Cookie %s => %s", log.Colorize(log.LIGHTMAGENTA, c.Name), c.String())
		ctx.Request.Header.Add("Cookie", c.String())
	}

	// Set Headers
	for k, v := range m.Request.Headers {
		key := strings.ToTitle(strings.Replace(k, "_", "-", -1))
		log.Debug("Spoofing Request Header %s => %s", log.Colorize(log.LIGHTMAGENTA, key), v)
		ctx.Request.Header.Set(key, v)
	}

	// This Writes all headers, setting status code - so call this last
	if m.Request.Method != "" {
		ctx.Request.Method = m.Request.Method
	}
}
開發者ID:roger2000hk,項目名稱:muxy,代碼行數:31,代碼來源:http_tamperer.go

示例6: titleCaseFirstLetter

func titleCaseFirstLetter(in string) string {
	out := ""
	out += string(in[0])
	out = strings.ToTitle(out)
	out += in[1:]
	return out
}
開發者ID:jmptrader,項目名稱:jra-go,代碼行數:7,代碼來源:utils.go

示例7: convertStruct

func convertStruct(in interface{}, val reflect.Value) *ConfigError {
	dict, ok := in.(map[string]interface{})
	if !ok || len(dict) != val.NumField() {
		return &ConfigError{ErrInvalidType, ""}
	}

	for k, from := range dict {
		to := val.FieldByName(strings.ToTitle(k[:1]) + k[1:])
		if !to.IsValid() {
			return &ConfigError{ErrInvalidType, ""}
		}

		convertor := convertFuncs.get(to)
		if convertor == nil {
			return &ConfigError{ErrInvalidType, ""}
		}

		if err := convertor(from, to); err != nil {
			if len(err.Field) > 0 {
				err.Field = fmt.Sprintf("%s.%s", k, err.Field)
			} else {
				err.Field = k
			}
			return err
		}
	}

	return nil
}
開發者ID:Archieeeeee,項目名稱:secretun,代碼行數:29,代碼來源:config.go

示例8: doLogGPUStatus

func doLogGPUStatus() {

	var stdout, stderr bytes.Buffer
	logGPU := func(toLog string) {
		cmd := exec.Command("nvidia-smi ",
			"-q", "-d", toLog, "|", "grep", "Gpu", "|", "cut", "-c35-36")
		cmd.Stdout = &stdout
		cmd.Stderr = &stderr

		err := RunCommandWithTimeout(5*time.Second, cmd)
		if err != nil {
			switch err.(type) {
			case TimeoutError:
				Incr(ServerRole+"-System", "GPUUnResponsive")
				return
			}
		} else {
			Log("System", strings.ToTitle(toLog),
				string(stdout.Bytes())+"::"+string(stderr.Bytes()))
		}
	}
	logGPU("MEMORY")
	logGPU("UTILIZATION")
	logGPU("PERFORMANCE")
	logGPU("ECC")
	logGPU("CLOCK")
	logGPU("TEMPERATURE")

}
開發者ID:thnguyn2,項目名稱:WebGPU,代碼行數:29,代碼來源:measure.go

示例9: addPlist

func addPlist(name string, config *Dashing) {
	var file bytes.Buffer
	t := template.Must(template.New("plist").Parse(plist))

	fancyName := config.Name
	if len(fancyName) == 0 {
		fancyName = strings.ToTitle(name)
	}

	aj := "false"
	if config.AllowJS {
		aj = "true"
	}

	tvars := map[string]string{
		"Name":        name,
		"FancyName":   fancyName,
		"Index":       config.Index,
		"AllowJS":     aj,
		"ExternalURL": config.ExternalURL,
	}

	err := t.Execute(&file, tvars)
	if err != nil {
		fmt.Printf("Failed: %s\n", err)
		return
	}
	ioutil.WriteFile(name+".docset/Contents/Info.plist", file.Bytes(), 0755)
}
開發者ID:technosophos,項目名稱:dashing,代碼行數:29,代碼來源:dashing.go

示例10: createTestData

func (tester *TestSearchSpaces) createTestData() ([]space.Space, error) {
	names := []string{"TEST_A", "TEST_AB", "TEST_B", "TEST_C"}
	for i := 0; i < 20; i++ {
		names = append(names, "TEST_"+strconv.Itoa(i))
	}

	spaces := []space.Space{}

	err := application.Transactional(tester.db, func(app application.Application) error {
		for _, name := range names {
			space := space.Space{
				Name:        name,
				Description: strings.ToTitle("description for " + name),
			}
			newSpace, err := app.Spaces().Create(context.Background(), &space)
			if err != nil {
				return err
			}
			spaces = append(spaces, *newSpace)
		}
		return nil
	})
	if err != nil {
		return nil, fmt.Errorf("Failed to insert testdata", err)
	}
	return spaces, nil
}
開發者ID:Ritsyy,項目名稱:almighty-core,代碼行數:27,代碼來源:search_spaces_blackbox_test.go

示例11: TitleCase

// TitleCase replace _ with space and upcase every word
func TitleCase(s string) string {
	ss := strings.Fields(strings.Replace(s, "_", " ", -1))
	for i := range ss {
		ss[i] = strings.ToTitle(ss[i][:1]) + ss[i][1:]
	}
	return strings.Join(ss, " ")
}
開發者ID:grafikdb,項目名稱:grafik-public,代碼行數:8,代碼來源:util.go

示例12: Forgot

func Forgot(w http.ResponseWriter, r *http.Request) {
	var err error
	var tmpl *plate.Template

	params := r.URL.Query()
	error := params.Get("error")
	error, _ = url.QueryUnescape(error)
	server := plate.NewServer()

	tmpl, err = server.Template(w)

	if err != nil {
		plate.Serve404(w, err.Error())
		return
	}

	tmpl.Bag["PageTitle"] = "Forgot Password"
	tmpl.Bag["Error"] = strings.ToTitle(error)
	tmpl.Bag["CurrentYear"] = time.Now().Year()
	tmpl.Bag["userID"] = 0

	tmpl.FuncMap["isNotNull"] = func(str string) bool {
		if strings.TrimSpace(str) != "" && len(strings.TrimSpace(str)) > 0 {
			return true
		}
		return false
	}
	tmpl.FuncMap["isLoggedIn"] = func() bool {
		return false
	}

	templates := append(TemplateFiles, "templates/auth/forgot.html")

	tmpl.DisplayMultiple(templates)
}
開發者ID:janiukjf,項目名稱:GoAdmin,代碼行數:35,代碼來源:authenticate.go

示例13: SignUp

func SignUp(w http.ResponseWriter, r *http.Request) {
	var err error
	var tmpl *plate.Template

	params := r.URL.Query()
	error := params.Get("error")
	error, _ = url.QueryUnescape(error)

	fname := params.Get("fname")
	fname, _ = url.QueryUnescape(fname)

	lname := params.Get("lname")
	lname, _ = url.QueryUnescape(lname)

	email := params.Get("email")
	email, _ = url.QueryUnescape(email)

	username := params.Get("username")
	username, _ = url.QueryUnescape(username)

	var submitted bool
	submitted, err = strconv.ParseBool(params.Get("submitted"))
	if err != nil {
		submitted = false
	}

	server := plate.NewServer()

	tmpl, err = server.Template(w)

	if err != nil {
		plate.Serve404(w, err.Error())
		return
	}

	tmpl.Bag["PageTitle"] = "Register"
	tmpl.Bag["Error"] = strings.ToTitle(error)
	tmpl.Bag["Fname"] = strings.TrimSpace(fname)
	tmpl.Bag["Lname"] = strings.TrimSpace(lname)
	tmpl.Bag["Email"] = strings.TrimSpace(email)
	tmpl.Bag["Username"] = strings.TrimSpace(username)
	tmpl.Bag["CurrentYear"] = time.Now().Year()
	tmpl.Bag["Submitted"] = submitted
	tmpl.Bag["userID"] = 0

	tmpl.FuncMap["isNotNull"] = func(str string) bool {
		if strings.TrimSpace(str) != "" && len(strings.TrimSpace(str)) > 0 {
			return true
		}
		return false
	}
	tmpl.FuncMap["isLoggedIn"] = func() bool {
		return false
	}

	templates := append(TemplateFiles, "templates/auth/signup.html")

	tmpl.DisplayMultiple(templates)

}
開發者ID:janiukjf,項目名稱:GoAdmin,代碼行數:60,代碼來源:authenticate.go

示例14: TestPaperKeyPhraseTypos

func TestPaperKeyPhraseTypos(t *testing.T) {
	p, err := MakePaperKeyPhrase(0)
	if err != nil {
		t.Fatal(err)
	}

	equivs := []string{
		p.String(),
		"   " + p.String(),
		p.String() + "  ",
		" " + p.String() + " ",
		"\t" + p.String() + "  ",
		" " + p.String() + "\t",
		strings.Join(strings.Split(p.String(), " "), "   "),
		strings.ToTitle(p.String()),
		strings.ToUpper(p.String()),
	}

	for _, s := range equivs {
		q := NewPaperKeyPhrase(s)
		version, err := q.Version()
		if err != nil {
			t.Fatal(err)
		}
		if version != 0 {
			t.Errorf("input: %q => version: %d, expected 0", s, version)
		}
		if q.String() != p.String() {
			t.Errorf("input: %q => phrase %q, expected %q", s, q.String(), p.String())
		}
		if len(q.InvalidWords()) > 0 {
			t.Errorf("input: %q => phrase %q, contains invalid words %v", s, q.String(), q.InvalidWords())
		}
	}

	// make a typo in one of the words
	w := strings.Fields(p.String())
	w[0] = w[0] + "qx"
	x := strings.Join(w, " ")
	q := NewPaperKeyPhrase(x)

	// version should still be ok
	version, err := q.Version()
	if err != nil {
		t.Fatal(err)
	}
	if version != 0 {
		t.Errorf("input: %q => version: %d, expected 0", x, version)
	}

	// but InvalidWords should return the first word as invalid
	if len(q.InvalidWords()) == 0 {
		t.Fatalf("input: %q => all words valid, expected %s to be invalid", x, w[0])
	}

	if q.InvalidWords()[0] != w[0] {
		t.Errorf("input: %q => invalid words %v, expected %s", x, q.InvalidWords(), w[0])
	}
}
開發者ID:qbit,項目名稱:client,代碼行數:59,代碼來源:paperkey_phrase_test.go

示例15: main

func main() {
	fmt.Println("Hello World")
	fmt.Println(strings.ToTitle("Hello World"))
	fmt.Println(strings.ToLower("hello world"))
	fmt.Println(strings.Replace("Hello World Hello World Hello World", "Hello", "Come", 2))
	fmt.Println(strings.Replace("    Aero    space", "    ", "", 2)) // Remove space
	fmt.Println(strings.TrimSpace("    Aero    space"))              // Also remove space but in the front
}
開發者ID:aurelien-git,項目名稱:go-experimentations,代碼行數:8,代碼來源:strings.go


注:本文中的strings.ToTitle函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。