Golang generates random numbers within a specified range, stitching split strings

Source: Internet
Author: User
package mainimport (    "fmt"    "strings"    "math/rand")func main() {    str := "zhongGuo_ZuiMeiLiDe_DiFang_ShiNaLi?"    s1 := strings.Fields(str)//将会利用 1 个或多个空白符号来作为动态长度的分隔符将字符串分割成若干小块    fmt.Println("-------s1------------",s1)    for _,val:=range s1  {        fmt.Println(val+"\n")    }    s2:=strings.Split(str,"_")//拆分字符串    fmt.Println("-------s2 len------------",len(s2))    for i:=0;i< len(s2);i++  {        fmt.Println(s2[i])    }    fmt.Println("-----------------")    for _,val:=range s2  {        fmt.Println(val)    }    s3:=strings.Join(s2,",")//拼接字符串    fmt.Println("------s3-----------",s3)    for i:=0;i<5;i++  {        a:=rand.Intn(10)//生成10以内的随机数        fmt.Println(a)    }    for i:=0;i<5;i++  {        a:=rand.Int()//生产随机数        fmt.Println(a)    }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.