Go基础--08 字符串

字符串

  1. string是数据类型,不是引用或指针类型
  2. string是只读的byte slice,len函数可以它所包含的byte数
  3. string的byte数组可以存放任何数据
package string_pra

import "testing"

func TestString(t *testing.T){
	var s string
	t.Log(s)
	s = "hello"
	t.Log(len(s))
	//s[1] = '3' //string是不可变的类型
	s = "\xE4\xB8\xA5"
	t.Log(s)
	t.Log(len(s)) //len求出里面的byte数
}

Unicode UTF8

  1. Unicode是一种字符集
  2. UTF8是unicode的存储实现(转换为字节序列的规则)

 

package string_func

import (
	"strconv"
	"strings"
	"testing"
)

func TestStringFunc(t *testing.T){
	s := "A,B,C"
	parts := strings.Split(s,",")
	for _,s := range parts {
		t.Log(s)
	}
	s = strings.Join(parts,"-")
	t.Log(s)
}

func TestStringToInt(t *testing.T){
	s := strconv.Itoa(10)
	t.Log(s)
	if i,err := strconv.Atoi("10"); err == nil{
		t.Log(10 + i)
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值