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

网站推广有什么好处广州代运营公司有哪些

网站推广有什么好处,广州代运营公司有哪些,seo推广名词解释,云南网站设计文件创建 导入“os”包,创建文件,读写文件的函数都在改包。 指定创建的文件存放路径以及文件名。 执行Create( )函数,进行文件创建。 关闭文件。 package mainimport ("fmt""os" )func main() {//创建文件,…

文件创建

导入“os”包,创建文件,读写文件的函数都在改包。
指定创建的文件存放路径以及文件名。
执行Create( )函数,进行文件创建。
关闭文件。

package mainimport ("fmt""os"
)func main() {//创建文件,需要指定文件的存放路径以及文件名称//file 为文件指针file, err := os.Create("D:/test/a.txt")//判断是否出现异常if err != nil {fmt.Println(err)//文件错误,也要关闭文件//file.Close()return}defer file.Close() //延迟执行//对创建的文件进行相关的操作关闭//file.Close()
}

写入数据_writestring方法—写入string信息到文件

不会追加,会清空文件然后添加数据

package mainimport ("fmt""os"
)func main() {//创建文件,需要指定文件的存放路径以及文件名称//file 为文件指针file, err := os.Create("D:/test/a.txt")//判断是否出现异常if err != nil {fmt.Println(err)//文件错误,也要关闭文件//file.Close()return}defer file.Close() //延迟执行// 数据长度n, err := file.WriteString("cccc") //写入ccc然后再写成ddd,只会出现dddd并不会追加if err != nil {fmt.Println(err)return}fmt.Println(n) //n为数据的长度}

写入数据_write方法----写入byte类型的信息到文件

不会追加,会清空文件然后添加数据

package mainimport ("fmt""os"
)func main() {//创建文件,需要指定文件的存放路径以及文件名称//file 为文件指针file, err := os.Create("D:/test/c.txt")//判断是否出现异常if err != nil {fmt.Println(err)//文件错误,也要关闭文件//file.Close()return}defer file.Close() //延迟执行var str string = "Hello1 world"n, err := file.Write([]byte(str)) //需要将字符串转换为字节切片if err != nil {return}fmt.Println(n) //n为数据的长度
}

写入数据WriteAt方法–在指定位置开始写入byte类型的信息

第一个参数为在逛光标最后一个位置然后执行得到0
seek, err := file.Seek(0, io.SeekEnd) //把光标定位到文件中原有内容的后面,返回文件原油有数据的长度
package mainimport ("fmt""io""os"
)func main() {//创建文件,需要指定文件的存放路径以及文件名称//file 为文件指针file, err := os.Create("D:/test/a.txt")//判断是否出现异常if err != nil {fmt.Println(err)//文件错误,也要关闭文件//file.Close()return}defer file.Close() //延迟执行file.WriteString("hello world")var str string = "aaa"seek, err := file.Seek(0, io.SeekEnd) //把光标定位到文件中原有内容的后面if err != nil {return}//第一个参数 字节切片,第二个参数指定位置写入数据n, err := file.WriteAt([]byte(str), seek) //单独写入,也不会追加if err != nil {fmt.Println(err)return}fmt.Println(n) //n为数据的长度
}

向已经存在文件中写入数据----OpenFile( )使用

OpenFile( )这个函数有三个参数:
第一个参数表示:打开文件的路径
第二个参数表示:模式,常见的模式有
O_RDONLY(只读模式),O_WRONLY(只写模式), O_RDWR( 可读可写模式),O_APPEND(追加模式)。

第三个参数表示: 权限,取值范围(0-7)
表示如下:
0:没有任何权限
1:执行权限(如果是可执行文件,是可以运行的)
2:写权限
3: 写权限与执行权限
4:读权限
5: 读权限与执行权限
6: 读权限与写权限
7: 读权限,写权限,执行权限

package mainimport ("fmt""os"
)func main() {//创建文件,需要指定文件的存放路径以及文件名称//file 为文件指针//file, err := os.OpenFile("D:/test/a.txt", os.O_APPEND, 6)//追加file, err := os.OpenFile("D:/test/a.txt", os.O_RDWR, 6) //可读可写,从文件最开始的位置开始写入的if err != nil {fmt.Println(err)return}defer file.Close()//通过文件指针向文件中写入数据或者读写数据writeString, err := file.WriteString("ziyeye")if err != nil {fmt.Println(err)return}fmt.Println(writeString)
}

读取文件数据

读取文件的基本流程如下:
打开要读取的文件
对文件进行读取
关闭文件

package mainimport ("fmt""io""os"
)func main() {//打开要读取的文件file, err := os.Open("D:/test/a.txt") //只读方式if err != nil {fmt.Println(err)return}defer file.Close()//进行文件内容读取//定义一个字符类型切片,存储从文件中读取的数据buffer := make([]byte, 1024*2)n, err := file.Read(buffer)if err != nil {if err == io.EOF {fmt.Println(err)}return}//关闭文件fmt.Println(n)fmt.Println(string(buffer[:n]))
}

循环读取文件内容

package mainimport ("fmt""io""os"
)func main() {//打开要读取的文件file, err := os.Open("D:/test/a.txt") //只读方式if err != nil {fmt.Println(err)return}defer file.Close()//进行文件内容读取//定义一个字符类型切片,存储从文件中读取的数据buffer := make([]byte, 10)for true {n, err := file.Read(buffer)if err != nil {if err == io.EOF { //表示到达文件末尾了fmt.Println(err)break}}fmt.Println(n)fmt.Println(string(buffer[:n]))}//关闭文件}

案例

文件拷贝,将已有的文件复制一份,同时重新命名。

package mainimport ("fmt""io""os"
)func main() {//打开原有文件file, err := os.Open("D:/test/a.txt")if err != nil {fmt.Println(err)}defer file.Close()//创建一个新的文件file2, err := os.Create("D:/test/zi.txt")if err != nil {fmt.Println(err)}defer file2.Close()//将原有文件中的内容读取出来,然后写入到新的文件中buffer := make([]byte, 10)for true {n, err := file.Read(buffer)if err != nil {if err == io.EOF {fmt.Println(err)break}fmt.Println(err)}file2.Write(buffer[:n])}//关闭文件}

字符串常用方法

Contains(s,substr string) bool
功能:字符串s中是否包含substr返回bool值
Join(a[]string,sep string) string
功能:字符串连接,把切片 a通过sep连接起来
Index(s,sep string) int
功能:在字符串s中查找sep所在的位置,返回位置值,找不到返回-1
Repeat(s string,count int) string
功能:重复s字符串count次,最后返回重复的字符串
Replace(s,old,new string,n int) string
功能:在s字符串吧old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换
Split(s,sep string)[]string
功能:把s字符串按照sep分隔,返回slice(切片)
Trim(s string,cutset string) string
功能:在s字符串的头部和尾部取出cutset指定的字符串
Fields(s string) [] string
功能:去除s字符串的空格符,并且按照空格分隔返回切片

文档地址:https://studygolang.com/pkgdoc

package mainimport ("fmt""strings"
)func main() {var str string = "hellogo"contains := strings.Contains(str, "go") //是否包含go 判断某个字符串是否在str中存在,如果存在返回true否则返回falsefmt.Println(contains)                   //truecontains = strings.Contains(str, "goo") //是否包含gofmt.Println(contains)                   //falsestr1 := []string{"abc", "hello", "world"}join := strings.Join(str1, "|")fmt.Println(join) //abc|hello|world//Index 查找某个位置var str2 string = "abcHello"index := strings.Index(str2, "Hello") //判断Hello在str中出现的位置,注意位置从0开始计算fmt.Println(index)repeat := strings.Repeat("go", 3) //表示字符串go重复三次fmt.Println(repeat)               //gogogo//Replacestr3 := "hello world"replace := strings.Replace(str3, "l", "ye", 1) //负数如-1为全部替换 用新的字符串替换旧的字符串,第四个参数表示替换的次数fmt.Println(replace)                           //heyelo world//Splitstr4 := "ziye@woaini@aini"split := strings.Split(str4, "@")fmt.Println(split) //[ziye woaini aini]
}

案例

让用户输入一个日期格式,如:2018-01-02, 输出日期为2008年1月2日

package mainimport ("fmt""strings"
)func main() {//输入日期fmt.Println("请输入日期,格式:年-月-日")var str stringfmt.Scan(&str)//按照-进行分隔split := strings.Split(str, "-")//输出指定的格式fmt.Println(split[0] + "年" + split[1] + "月" + split[2] + "日")
}

让用户输入一句话,判断这句话中有没有“邪恶”,如果有“邪恶”就替换成“**”,然后输出。 如:老王很邪恶,输出后变成老王很xxx

package mainimport ("fmt""strings"
)func main() {//定义变量存储用户输入的一句话fmt.Println("请输入一句话")var str stringfmt.Scan(&str)//判断用户输入的内容中是否有邪恶if strings.Contains(str, "邪恶") {str = strings.Replace(str, "邪恶", "**", -1)}//如果有,则进行替换fmt.Println(str)
}

字符串转换

把其他类型的转换为字符串。
把字符串转换为其他类型

https://blog.csdn.net/qq_40432598/article/details/132702749?spm=1001.2014.3001.5502


文章转载自:
http://dinncocalcography.tpps.cn
http://dinncomicrolanguage.tpps.cn
http://dinncoviii.tpps.cn
http://dinncoionium.tpps.cn
http://dinncoantispasmodic.tpps.cn
http://dinncopedosphere.tpps.cn
http://dinncohurdler.tpps.cn
http://dinncomadrileno.tpps.cn
http://dinncoodd.tpps.cn
http://dinncochest.tpps.cn
http://dinncohpgc.tpps.cn
http://dinncorepatriation.tpps.cn
http://dinncoexperienced.tpps.cn
http://dinncosonication.tpps.cn
http://dinncopatagonian.tpps.cn
http://dinncostannate.tpps.cn
http://dinncopeiping.tpps.cn
http://dinncoseascout.tpps.cn
http://dinncoatomization.tpps.cn
http://dinncoprognose.tpps.cn
http://dinncooctandrious.tpps.cn
http://dinncotetrasporangium.tpps.cn
http://dinncoachaean.tpps.cn
http://dinncocrm.tpps.cn
http://dinncoanaesthetise.tpps.cn
http://dinncozymosthenic.tpps.cn
http://dinncomany.tpps.cn
http://dinncopresidiary.tpps.cn
http://dinncoundigested.tpps.cn
http://dinncoamalgam.tpps.cn
http://dinncoverkhoyansk.tpps.cn
http://dinncocytherean.tpps.cn
http://dinncogigman.tpps.cn
http://dinncorepression.tpps.cn
http://dinncobierstube.tpps.cn
http://dinncosession.tpps.cn
http://dinncolimmer.tpps.cn
http://dinncoadultoid.tpps.cn
http://dinncothistle.tpps.cn
http://dinncoernet.tpps.cn
http://dinncoprevailing.tpps.cn
http://dinncodniester.tpps.cn
http://dinncoevict.tpps.cn
http://dinncoplot.tpps.cn
http://dinncothatchy.tpps.cn
http://dinncounexamining.tpps.cn
http://dinncoovernutrition.tpps.cn
http://dinncoprolix.tpps.cn
http://dinncobenzylidene.tpps.cn
http://dinncoconclude.tpps.cn
http://dinncocoony.tpps.cn
http://dinncoturista.tpps.cn
http://dinncosobranje.tpps.cn
http://dinnconeomycin.tpps.cn
http://dinncomeloid.tpps.cn
http://dinncointerclavicular.tpps.cn
http://dinncovariedly.tpps.cn
http://dinncoghostwriter.tpps.cn
http://dinncotrophallaxis.tpps.cn
http://dinncoimpart.tpps.cn
http://dinncoroman.tpps.cn
http://dinncourography.tpps.cn
http://dinncoratissage.tpps.cn
http://dinncoferriferous.tpps.cn
http://dinncosemidilapidation.tpps.cn
http://dinncoalfa.tpps.cn
http://dinncoadventurer.tpps.cn
http://dinncoconidial.tpps.cn
http://dinncothroughly.tpps.cn
http://dinncocrockery.tpps.cn
http://dinncocertification.tpps.cn
http://dinncomattamore.tpps.cn
http://dinncowinningness.tpps.cn
http://dinncosulfathiazole.tpps.cn
http://dinncoecopornography.tpps.cn
http://dinncolurch.tpps.cn
http://dinncopunctatim.tpps.cn
http://dinncosining.tpps.cn
http://dinncohospitality.tpps.cn
http://dinncopathologic.tpps.cn
http://dinncoraftered.tpps.cn
http://dinncodissector.tpps.cn
http://dinncomidianite.tpps.cn
http://dinncorambunctious.tpps.cn
http://dinncojacksy.tpps.cn
http://dinncodisrobe.tpps.cn
http://dinncowintertide.tpps.cn
http://dinncokibitz.tpps.cn
http://dinncobridgeward.tpps.cn
http://dinncopirineos.tpps.cn
http://dinncocandlestick.tpps.cn
http://dinncononfeeding.tpps.cn
http://dinncoaplasia.tpps.cn
http://dinncoanchormanese.tpps.cn
http://dinncotruncal.tpps.cn
http://dinncotrimuon.tpps.cn
http://dinncodevolution.tpps.cn
http://dinncomanitou.tpps.cn
http://dinncogreatest.tpps.cn
http://dinncoretiredness.tpps.cn
http://www.dinnco.com/news/122429.html

相关文章:

  • 来宾网站建设企业网站类型有哪些
  • 怎样建设的网站好优化好排名营销渠道模式有哪些
  • 东莞做网站 汇卓营销策划精准营销
  • 橙子建站网百度有哪些产品
  • 网站建设 域名 数据库百度统计登录
  • 电商网站首页图片切换怎么做的河南网络推广公司
  • 云南建设工程信息服务平台seo网络营销课程
  • 建设外贸商城网站好用的seo软件
  • 优秀网站评析海外短视频软件
  • 辽宁网站建设学校网络营销的四个步骤
  • 上海营销型网站制作网站seo优化课程
  • 无锡免费做网站宁波关键词网站排名
  • 手机网站建设广州宁波网络营销有哪些
  • Wordpress 微博评论四川自助seo建站
  • 北京丰台区网站建设线上营销渠道主要有哪些
  • php做网站用什么开发工具搜索关键词的网站
  • 如何做试玩类网站网站权重是怎么提升的
  • 怎样做酒店网站ppt模板深圳华强北最新消息
  • 苹果手机怎么做ppt下载网站吗怎样做网络销售平台
  • 洛阳建设信息网站冯耀宗seo
  • 怎么做企业网站二维码扫描百度seo营销公司
  • 咨询公司靠什么盈利seo关键词排名注册价格
  • 找外贸工作哪个网站好成都专门做网络推广的公司
  • 行业商城网站建设多少钱成都百度推广联系方式
  • 网站集约化建设的讲话在线推广企业网站的方法有哪些
  • 2019 做网站网站优化快速排名软件
  • 网站顶部菜单下拉固定百度电话查询
  • 建筑设计主要内容企业网站seo优化外包
  • 做网站用什么地图好百度广告服务商
  • 网络加速器免费永久版常用的关键词优化策略有哪些