• (Go)07.strings与strconv的示例


     1 package main
     2 import (
     3   "strconv"
     4   "fmt"
     5   "strings"
     6 )
     7 func main() {
     8 
     9     str := "Hello World test!"
    10     result := strings.Replace(str, "World", "golang", 1)
    11     fmt.Println(result)
    12 
    13     count := strings.Count(str, "o")
    14     fmt.Println(count)
    15 
    16     result = strings.Repeat(str, 3)
    17     fmt.Println(result)    
    18 
    19     result = strings.ToUpper(str)
    20     fmt.Println(result)    
    21 
    22     result = strings.ToLower(str)
    23     fmt.Println(result)    
    24 
    25     result = strings.TrimSpace(str)
    26     fmt.Println("trimSpace:" ,result)
    27 
    28     result = strings.Trim(str, " 
    
    ")
    29     fmt.Println("trim:" ,result)
    30 
    31     result =  strings.TrimLeft(str, " 
    
    ")
    32     fmt.Println("trimleft:" ,result)
    33 
    34     result =  strings.TrimRight(str, " 
    
    ")
    35     fmt.Println("trimright:" ,result)
    36 
    37     splitResult := strings.Fields(str)
    38     for i := 0; i < len(splitResult); i++ {
    39         fmt.Println(splitResult[i])
    40     }
    41     str2 := strings.Join(splitResult, "l")
    42     fmt.Println("join:", str2)
    43 
    44     str2 = strconv.Itoa(1000)
    45     fmt.Println("itoa:", str2)
    46 
    47     number, err := strconv.Atoi(str2)
    48     if err != nil {
    49         fmt.Println("can not convert to int,", err)
    50         return
    51     }
    52     fmt.Println("number:", number)
    53 }

    输出结果:

  • 相关阅读:
    <context-param>与<init-param>的区别与作用(转自青春乐园)(
    使用Derby ij客户端工具
    转载 Ofbiz 入门教程
    数据库中插入和读取图片
    事务的使用
    存储过程
    触发器 的使用
    JS面试题及答案
    课程主页面三个接口开发
    增加media文件配置
  • 原文地址:https://www.cnblogs.com/lvcisco/p/10334878.html
Copyright © 2020-2023  润新知