首页 > 其他分享 >0120-Go-字符串函数

0120-Go-字符串函数

时间:2022-11-28 22:24:59浏览次数:64  
标签:Index 函数 0120 Replace 字符串 test Go

环境

  • Time 2022-08-25
  • Go 1.19

前言

说明

参考:https://gobyexample.com/string-functions

目标

使用 Go 语言的字符串函数。

示例

package main

import (
    "fmt"
    s "strings"
)

var p = fmt.Println

func main() {

    p("Contains:  ", s.Contains("test", "es"))
    p("Count:     ", s.Count("test", "t"))
    p("HasPrefix: ", s.HasPrefix("test", "te"))
    p("HasSuffix: ", s.HasSuffix("test", "st"))
    p("Index:     ", s.Index("test", "e"))
    p("Join:      ", s.Join([]string{"a", "b"}, "-"))
    p("Repeat:    ", s.Repeat("a", 5))
    p("Replace:   ", s.Replace("foo", "o", "0", -1))
    p("Replace:   ", s.Replace("foo", "o", "0", 1))
    p("Split:     ", s.Split("a-b-c-d-e", "-"))
    p("ToLower:   ", s.ToLower("TEST"))
    p("ToUpper:   ", s.ToUpper("test"))
}

总结

使用 Go 语言的字符串函数。

附录

标签:Index,函数,0120,Replace,字符串,test,Go
From: https://www.cnblogs.com/jiangbo4444/p/16933835.html

相关文章

  • 0122-Go-模板字符串
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/text-templates目标使用Go语言的模板字符串。示例packagemainimport("os""t......
  • 0123-Go-正则表达式
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/regular-expressions目标使用Go语言的正则表达式。示例packagemainimport( "bytes" ......
  • 0124-Go-JSON 转换
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/json目标使用Go语言的JSON。简单值packagemainimport("encoding/json""fmt......
  • 0125-Go-XML 转换
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/xml目标使用Go语言的XML。示例packagemainimport("encoding/xml""fmt")......
  • json字符串转json对象三种方式
    //1,js自带的eval函数,其中需要添加小括号eval('('+str+')');functionstrToJson(str){varjson=eval('('+str+')');returnjson;}//2,newFunction形式fun......
  • PYTHON 字符串
    1.1字符串字符串类型是:str,是有顺序的字符序列,索引从0开始。1.2字符串的表示方法1.2.1普通字符串用单引号或双引号括起来的字符序列a="hello"b='hello'1.2.......
  • go zap日志库
    https://github.com/labring/sealos/blob/main/pkg/utils/logger/logger.gopackagelogger   import( "fmt" "os" "strings"......
  • go源码学习(一):数据结构-数组
    数组是相同类型元素的集合,在内存中对应一块连续的内存空间。数组类型是通过存储的元素类型以及能够存储的大小两个维度来决定的,一旦声明之后大小就不可更改。初始化go语......
  • Android Google开源库——Volley的简单使用
    介绍一下AndroidGoogle开源库——Volley的简单使用volley 项目地址 ​​https://github.com/smanikandan14/Volley-demo​​JSON,图像等的异步下载;网络请求的排序(sc......
  • jQuery插件FullCalendar日程表实现可扩展Google日历功能
    这个介绍jQuery日历FullCalendar插件是一个非常不错的日历工具,可用于制作日程表或计划安排等,可扩展Google日历功能,制作个性化的日程表,同时可绑定点击事件或拖动事件,使用非常......