当前位置: 首页>>代码示例>>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;未经允许,请勿转载。