zoukankan      html  css  js  c++  java
  • 38_Go基础_1_5 string

     1 package main
     2 
     3 import "fmt"
     4 
     5 func main() {
     6     /*
     7         字符串:
     8         1.概念:多个byte的集合,理解为一个字符序列
     9         2.语法:使用双引号
    10             "abc","hello","A"
    11                 也可以使用``
    12         3.编码问题
    13                 计算机本质只识别0和1
    14                 A:65,B:66,C:67...
    15                 a:97,b:98...
    16             ASCII(美国标准信息交换码)
    17 
    18             中国的编码表:gbk,兼容ASCII
    19 20 21             Unicode编码表:号称统一了全世界
    22                 UTF-8,UTF-16,UTF-32...
    23 
    24         4.转义字符:\
    25             A:有一些字符,有特殊的作用,可以转义为普通的字符
    26                 \',\'
    27             B:有一些字符,就是一个普通的字符,转义后有特殊的作用
    28                 \n,换行
    29                 \t,制表符
    30     */
    31 
    32     //1.定义字符串
    33     var s1 string
    34     s1 = "王二狗"
    35     fmt.Printf("%T,%s\n", s1, s1) // string,王二狗
    36 
    37     s2 := `Hello World`
    38     fmt.Printf("%T,%s\n", s2, s2) // string,Hello World
    39 
    40     //2.区别:'A',"A"
    41     v1 := 'A'
    42     v2 := "A"
    43     vt := []rune(v2)
    44     fmt.Printf("%T,%d\n", v1, v1)        // int32,65
    45     fmt.Printf("%T,%s\n", v2, v2)        // string,A
    46     fmt.Printf("%T,%#v\n", vt[0], vt[0]) // int32,65
    47 
    48     v3 := ''
    49     fmt.Printf("%T,%d,%c,%q\n", v3, v3, v3, v3) // int32,20013,中,'中'
    50 
    51     //3.转义字符
    52     fmt.Println("\"HelloWorld\"") // "HelloWorld"
    53     fmt.Println("Hello\nWor\tld")
    54 
    55     fmt.Println(`He"lloWor"ld`) // He"lloWor"ld
    56     fmt.Println("Hello`Wor`ld") // Hello`Wor`ld
    57 }
  • 相关阅读:
    VS2005编译mysql5.1.68
    用boost库实现traceroute小工具
    linux内核选项部分翻译
    linux 内核中的锁机制RCU
    先装windows 还是linux ?
    U盘装ubuntu
    编译linux内核3.0
    root密码丢失了怎么办?
    linux配置文件
    新一代linux文件系统btrfs
  • 原文地址:https://www.cnblogs.com/luwei0915/p/15617511.html
Copyright © 2011-2022 走看看