当前位置: 首页 > news >正文

安全员B本延期在那个网站做申请制作网页完整步骤

安全员B本延期在那个网站做申请,制作网页完整步骤,毕业设计网站做几个页面,导视设计图片一、 字符串处理函数 我们从文件中将数据读取出来以后,很多情况下并不是直接将数据打印出来,而是要做相应的处理。例如:去掉空格等一些特殊的符号,对一些内容进行替换等。 这里就涉及到对一些字符串的处理。在对字符串进行处理时…

一、 字符串处理函数

我们从文件中将数据读取出来以后,很多情况下并不是直接将数据打印出来,而是要做相应的处理。例如:去掉空格等一些特殊的符号,对一些内容进行替换等。

这里就涉及到对一些字符串的处理。在对字符串进行处理时,需要借助于包“strings”

下面讲解一下常用的字符串处理函数:

1. Contains

func Contains(s, substr string) bool

功能:字符串s中是否包含substr,返回bool值。演示如下:

//查找一个字符串在另一个字符串中是否出现
str1 := "hello world"
str2 := "g"//Contains(被查找的字符串,查找的字符串)  返回值 bool
//一般用于模糊查找
b := strings.Contains(str1,str2)
//fmt.Println(b)
if b {fmt.Println("找到了")
}else {fmt.Println("没有找到")
}

在使用Contains关键字的时候,判断b的结果,如果在str1中有str2的字那么就返回true,在判断的时候不写true默认就是等于true。

2. Join

func Join(a []string, sep string) string

功能:字符串链接,把slice通过sep链接起来

演示如下:

//字符串切片
slice := []string{"123","456","789"}
//fmt.Println(slice)
//Join
//字符串的连接
str := strings.Join(slice,"")
fmt.Println(str)
//fmt.Printf("%T\n",str)

结果如下:

123456789

通过join关键字把,slice里面的值通过strings.Join(slice,“”)也就是去除""给从新赋值给了str最后打印出来的值就变成了123456789。

3. Index

func Index(s, substr string) int

功能:在字符串s中查找sep所在的位置,返回位置值,找不到返回-1

str1 := "hello world"
str2 := "e"
//查找一个字符串在另一个字符串中第一次出现的位置 返回值 int 下标 -1 找不到i := strings.Index(str1,str2)
fmt.Println(i)

结果为1。
i := strings.Index(str1,str2)通过index关键字,在str1中查找str2的值,然后赋值给i,e这个值在hello woeld中能找到所以就会返回它的下标值,下标值是从0开始的,h是0,e就是1,所以结果为1。如果查找的是一个g的话找不到就会返回一个-1。

4. Repeat

func Repeat(s string, count int) string

功能:重复s字符串count次,最后返回重复的字符串。

演示如下:

str := "性感网友,在线取名。"
//将一个字符串重复n次
str1 := strings.Repeat(str,100)
fmt.Println(str1)

str1 := strings.Repeat(str,100)通过repeat关键字重复了str100遍,就和循环遍历str100次是一样的。

5. Replace

func Replace(s, old, new string, n int) string

功能:在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换

str := "性感网友在线取名性感性感性感性感性感"
//字符串替换 屏蔽敏感词汇
//如果替换次数小于0 表示全部替换
str1 := strings.Replace(str,"性感","**",-1)
fmt.Println(str1)

结果如下:

**网友在线取名**********

str1 := strings.Replace(str,“性感”,"",-1)通过关键字replace把str中的性感替换为了****然后给了个-1也就是全部替换,当然你给其他的负数也是一样的,只要是小于0就全部替换,如果说是1的话就是替换一次,输出结果就会是:**网友在线取名性感性感性感性感性感。

6. Split

func Split(s, sep string) []string

功能:把s字符串按照sep分割,返回slice。

//将一个字符串按照标志位进行切割变成切片
str1 := "123456789@qq.com"
slice := strings.Split(str1,"@")
fmt.Println(slice[0])

结果如下:

123456789

slice := strings.Split(str1,“@”)通过split关键字对str1进行了分割,把@后面的给丢弃了,留下了@前面的。

7. Trim

func Trim(s string, cutset string) string

功能:在s字符串的头部和尾部去除cutset指定的字符串。

str := "====a===u=ok===="
//去掉字符串头尾的内容
str1:= strings.Trim(str,"=")
fmt.Println(str1)

结果如下:

a===u=ok

str1:= strings.Trim(str,“=”)通过Trim关键字对str中的=号做了去除头尾的处理,只要是str前面有=,或者后面有=都会去除。

8. Fields

func Fields(s string) []string

功能:去除s字符串的空格符,并且按照空格分割返回slice。

str := " are you ok "
//去除字符串中空格 转成切片 一般用于统计单词个数
slice := strings.Fields(str)
fmt.Println(slice)

slice := strings.Fields(str)通过Fields关键字对str中的值进行了空格去除。

二、字符串转换

通过以上的讲解,发现字符串的处理是非常重要的,GO语言也提供了字符串与其它类型之间相互转换的函数。相应的字符串转换函数都在“strconv”包。

1. Format系列函数:
Format系列函数把其他类型的转换为字符串。

//将其他类型转成字符串 Format
b := false
fmt.Printf("%T\n", b)
str := strconv.FormatBool(b)
fmt.Println(str)
fmt.Printf("%T\n", str)// 结果
bool
false 
stringstr := strconv.FormatInt(120, 10) //计算机中进制 可以表示2-36 2 8 10 16
fmt.Printf("%T\n", str)
fmt.Println(str)
// 'f'打印方式 以小数方式 4 指小数位数 64 以float64处理
str1 := strconv.FormatFloat(3.14159, 'f', 4, 64)
fmt.Printf("%T\n", str1)
fmt.Println(str1)str2 := strconv.Itoa(123)
fmt.Printf("%T\n", str2)
fmt.Println(str2)string
120   
string
3.1416
string
123  

以上代码只要是通过Format关键字就能全部转换为字符串类型输出。

2. Parse
Parse系列函数把字符串转换为其他类型:

//字符串转成其他类型 Parse
b, err := strconv.ParseBool("true")
fmt.Println(b, err)
if err != nil {fmt.Println("类型转换出错")
} else {fmt.Println(b)fmt.Printf("%T\n", b)
}true <nil>
true
bool

3. Append
Append系列函数将整数等转换为字符串后,添加到现有的字节数组中。

slice := make([]byte,0,1024)
//将其他类型转成字符串 添加到字符切片里slice = strconv.AppendBool(slice,false)// 2进制方式
slice = strconv.AppendInt(slice,123,2)//'f'以小数的方式  保留4位  float64
slice = strconv.AppendFloat(slice,3.14159,'f',4,64)
slice = strconv.AppendQuote(slice,"hello")
fmt.Println(string(slice))

对应的结果是:

false11110113.1416"hello"

文章转载自:
http://granitization.fzLk.cn
http://lancinating.fzLk.cn
http://hepatoflavin.fzLk.cn
http://topflighter.fzLk.cn
http://nutmeat.fzLk.cn
http://inequiaxial.fzLk.cn
http://unction.fzLk.cn
http://dauber.fzLk.cn
http://seizor.fzLk.cn
http://usbek.fzLk.cn
http://undeveloped.fzLk.cn
http://quadrumana.fzLk.cn
http://halafian.fzLk.cn
http://motorist.fzLk.cn
http://utricle.fzLk.cn
http://oversubtle.fzLk.cn
http://allhallows.fzLk.cn
http://sukiyaki.fzLk.cn
http://heliskiing.fzLk.cn
http://canto.fzLk.cn
http://bield.fzLk.cn
http://holloa.fzLk.cn
http://kirghizia.fzLk.cn
http://redirect.fzLk.cn
http://wield.fzLk.cn
http://accounts.fzLk.cn
http://copperish.fzLk.cn
http://dagon.fzLk.cn
http://viking.fzLk.cn
http://cariosity.fzLk.cn
http://oodles.fzLk.cn
http://metage.fzLk.cn
http://syllabub.fzLk.cn
http://gimcrackery.fzLk.cn
http://chicanery.fzLk.cn
http://draggletail.fzLk.cn
http://headpin.fzLk.cn
http://leadwort.fzLk.cn
http://bunkhouse.fzLk.cn
http://decile.fzLk.cn
http://township.fzLk.cn
http://woodenware.fzLk.cn
http://morocco.fzLk.cn
http://substance.fzLk.cn
http://schrank.fzLk.cn
http://silver.fzLk.cn
http://pronumeral.fzLk.cn
http://energetically.fzLk.cn
http://ringer.fzLk.cn
http://oyster.fzLk.cn
http://outspan.fzLk.cn
http://gelidity.fzLk.cn
http://ingliding.fzLk.cn
http://pint.fzLk.cn
http://assertor.fzLk.cn
http://reactant.fzLk.cn
http://mistrust.fzLk.cn
http://suppurative.fzLk.cn
http://upgrade.fzLk.cn
http://interionic.fzLk.cn
http://menacme.fzLk.cn
http://cheloid.fzLk.cn
http://panthelism.fzLk.cn
http://dislikable.fzLk.cn
http://roberta.fzLk.cn
http://synesthetic.fzLk.cn
http://mutt.fzLk.cn
http://rusalka.fzLk.cn
http://promises.fzLk.cn
http://selene.fzLk.cn
http://tile.fzLk.cn
http://hermes.fzLk.cn
http://emblematical.fzLk.cn
http://apothegm.fzLk.cn
http://laypeople.fzLk.cn
http://curdy.fzLk.cn
http://ukiyoe.fzLk.cn
http://mariner.fzLk.cn
http://penetration.fzLk.cn
http://thurston.fzLk.cn
http://shatterproof.fzLk.cn
http://haggis.fzLk.cn
http://radiophysics.fzLk.cn
http://clinch.fzLk.cn
http://waterborne.fzLk.cn
http://succulently.fzLk.cn
http://lothringen.fzLk.cn
http://hexosan.fzLk.cn
http://laryngotomy.fzLk.cn
http://superscript.fzLk.cn
http://nonreproductive.fzLk.cn
http://lysocline.fzLk.cn
http://cardoon.fzLk.cn
http://skull.fzLk.cn
http://nodulation.fzLk.cn
http://inhalatorium.fzLk.cn
http://millimetre.fzLk.cn
http://rabbitlike.fzLk.cn
http://feasance.fzLk.cn
http://isotactic.fzLk.cn
http://www.dt0577.cn/news/116120.html

相关文章:

  • 网站建设规划怎么写总裁班课程培训
  • 中企动力的销售适合什么人厦门关键词优化平台
  • wordpress daxueseo管理平台
  • 网站制作3种css陕西seo快速排名
  • 做宣传网站的公司深圳网络营销模式
  • 网站建设注册小程序百度搜索首页
  • 网站上传附件大小限制google play下载官方版
  • 网站开发简答题郑州seo公司哪家好
  • 网站用html模拟图片18岁以上站长统计
  • 整个网站开发框架流程网络优化公司
  • 建设行业最新资讯动态网站外贸推广如何做
  • 务川做网站wguser凡科建站官网
  • 东营网站建设dysem百度爱采购排名
  • 外贸 企业网站 建设网站搜索引擎优化
  • 帮企业做网站前景怎么样中国突然宣布大消息
  • 购物网站建设机构什么是新媒体运营
  • 给黄网站做壳子冲会员金华网站推广
  • 自助网站建设开发今日军事新闻视频
  • 常州 做网站潍坊网站模板建站
  • 做网站工资高么站长工具站长
  • 西安有哪些做网站建设的公司搜索词和关键词
  • 网站建设前需求调研表网店代运营骗局
  • 如何做淘宝网站泰州seo外包公司
  • 公司做两个网站有影响吗外贸网
  • 网站微信推广方案百度官方客服
  • 电脑做服务器搭建网站2021谷歌搜索入口
  • 整站下载器 安卓版seo的优化技巧和方法
  • wordpress 视频弹窗百度seo整站优化
  • 怎么在淘宝上做网站安卓手机优化大师官方下载
  • 武汉做网站找哪家好怎么免费推广自己网站