package main;

import (
"fmt"
"strings"
) type person struct {
name string;
age int;
} func main() {
//判断是否包含某个子字符串
fmt.Println(strings.Contains("hello", "he"));
//统计子符串的次数
fmt.Println(strings.Count("hello hello", "ll"));
//判断前缀字符串
fmt.Println(strings.HasPrefix("hello", "he"));
//判断后缀字符串
fmt.Println(strings.HasSuffix("hello", "lo"));
//找查子符串第一次出现的位置,不存在返回-1
fmt.Println(strings.Index("hello", "el"));
//拼接字符串
fmt.Println(strings.Join([]string{"a","b","c"}, ","));
//重复字符串
fmt.Println(strings.Repeat("hello", 3));
//替换前n个字符串
fmt.Println(strings.Replace("hello", "l", "x", 1));
//替换所有字符串
fmt.Println(strings.Replace("hello", "l", "x", -1));
//分割字符串,返回slice
fmt.Println(strings.Split("a,b,c", ","));
//转为小写
fmt.Println(strings.ToLower("HELLO"));
//转为大写
fmt.Println(strings.ToUpper("hello"));
//获取字符串长度
fmt.Println(len("hello")); //格式化输出
var a = person{name:"test",age:22};
//打印出结构体
fmt.Printf("%v\n", a);
//打印出结构体成员名称和值
fmt.Printf("%+v\n", a);
//格式化输出Go语法表示方式
fmt.Printf("%#v\n", a);
//输出类型
fmt.Printf("%T\n", a);
//格式化布尔型变量
fmt.Printf("%t\n", true);
//输出整型
fmt.Printf("%d\n", 123);
//输出二进制
fmt.Printf("%b\n", 10);
//输出对应字符
fmt.Printf("%c\n", 65);
//输出十六进制表示
fmt.Printf("%x\n", 256);
//输出浮点数
fmt.Printf("%f\n", 12.45);
//科学计数法
fmt.Printf("%e\n", 1230000000.0);
fmt.Printf("%E\n", 1230000000.0);
//输出字符串
fmt.Printf("%s\n", "hello");
//输出指针的值
fmt.Printf("%p\n", &a);
//控制输出宽度,并用0补齐,输出默认右对齐的
fmt.Printf("%020d\n", 345);
}

  

go语言中的strings常用函数和格式化输出的更多相关文章

  1. C语言中getopt()和getopt_long()函数的用法

    一.参考文章 1.C语言中getopt()和getopt_long()函数的用法 2.linux 中解析命令行参数 (getopt_long用法) 二.调试经验

  2. Python语言中enumerate()及zip()函数的使用例子

    在Python编程语言中,enumerate()及zip()是两个常用的内置函数,这两个函数功能类似,但又有所区别,下面通过两个例子分别进行说明. enumerate()函数 该函数在字面上是枚举.列 ...

  3. ZH奶酪:C语言中malloc()和free()函数解析

    1.malloc()和free()的基本介绍 (1)函数原型及说明 void *malloc(long NumBytes) 该函数分配了NumBytes个字节,并返回了指向这块内存的指针.如果分配失败 ...

  4. go语言学习 strings常用函数

    strings包中的函数用法 参考链接http://studygolang.com/articles/88 1.strings.replace() 函数原型 func Replace(str1, ol ...

  5. Java String 函数常用操作 & format() 格式化输出,代码详解

    package _String_; import java.util.*; import java.math.*; import java.lang.*; public class _Strings ...

  6. python基础之常用模块以及格式化输出

    模块简介 模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要 ...

  7. python的print函数的格式化输出

    使用print函数的时候,可以像C一样格式化输出,同时还支持参数化输出 print('%s' % ("CooMark")) print('整数|%d|' % (123)) prin ...

  8. C语言中sizeof、strlen函数的部分理解

    一.测试环境 Win10 + Visual Studio 2017 二.测试代码 #include "pch.h" #include <iostream> #inclu ...

  9. 对c语言中malloc和free函数的理解

    最近在复习c语言的时候再次用到了malloc函数和free函数,此处着讲解一下自己对这两个函数的理解和认识. 一. malloc函数和free函数的基本概念和基本的用法 对于malloc函数: 1.  ...

随机推荐

  1. requirejs源码分析

  2. Bug : Cannot evaluate ...toString()

  3. unity 数学公式

    Mathf.Abs绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 f ...

  4. iOS Dev (25) 解决“The executable was signed with invalid entitlements.”问题

    2014-01-10 10:34 5240人阅读 评论(1) 收藏 举报   目录(?)[+]   iOS Dev (25) 解决“The executable was signed with inv ...

  5. anchor_generator.proto:11:3: Expected "required", "optio nal", or "repeated"

    转自:https://github.com/tensorflow/models/issues/1834 When I use the commond " protoc object_dete ...

  6. Java happen-before

    下面是happens-before原则规则: 程序次序规则:一个线程内,按照代码顺序,书写在前面的操作先行发生于书写在后面的操作: 锁定规则:一个unLock操作先行发生于后面对同一个锁额lock操作 ...

  7. node 跨域

    app.post('/api/list',function(req, res){ let reqOrigin = req.headers.origin; // request响应头的origin属性 ...

  8. Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources 在我的myeclipse中新建maven工程总出现这个问题

    只需在下图中更改代码 更改后是这样的: <plugin> <groupId>org.apache.maven.plugins</groupId> <artif ...

  9. 魅族手机USB调试无法打开、log无法打印

    MEIZU 在打开usb调试允许时,总提示:because an app is oobscuring a premision request, Setting can't verify your re ...

  10. linux系统修改系统时间与时区

    有装过Linux系统的人,可能都会有这样的经历,就是该机器安装windows系统时,时间正确,但是安装了linux系统后,尽管时区选择正确,也会发现系统时间不对.这是由于安装系统时采用了UTC,那么什 ...