常用代码

100次阅读

共计 1391 个字符,预计需要花费 4 分钟才能阅读完成。

字符串分割
//php
$str = 'one,two,three,four';
$re = explode(',',$str);//Array['one','two','three','four',]

//js
var str = "2:3:4:5".split(":")    // 将返回 ["2", "3", "4", "5"]

//Golang
 s := strings.Split("abc,abc", "")
 fmt.Println(s, len(s))//[a b c , a b c] 7 // 返回 7 个数组元素
 
//python
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
str = "Line1-abcdef \nLine2-abc \nLine4-abcd";
print str.split( );       # 以空格为分隔符,包含 \n
print str.split(' ', 1); # 以空格为分隔符,分隔成两个
数组转字符串
//php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);// "lastname,email,phone"


//js
var array = ["2", "3", "4", "5"];
var str = array.join(",");//"2,3,4,5"

//Golang
 res_two := []string {"get", "post"}
    fmt.Println(strings.Join(res_one, ","))//"get,post"
    
//python
list3 =['www', 'google', 'com']
str4 = ".".join(list3) //www.google.com
类型转换
//php
$str = "100";
$int = (int)$str;100
$str1 = (string)$int;//"100"

//js
var a = parseInt("10");// 10
var b = String(12345);// "12345"

//Golang
#string 到 int
int,err:=strconv.Atoi(string)
#string 到 int64
int64, err := strconv.ParseInt(string, 10, 64)
#int 到 string
string:=strconv.Itoa(int)
#int64 到 string
string:=strconv.FormatInt(int64,10)

//python
字符串 str 转换成 int: int_value = int(str_value)
int 转换成字符串 str: str_value = str(int_value)

循环 for

//Golang
 countryCapitalMap := map[string]string{"France": "Paris", "Italy": "Rome", "Japan": "Tokyo", "India": "New delhi"}

        fmt.Println("原始地图")
    
    /* 打印地图 单一值的时候引用 index */
    for country := range countryCapitalMap {fmt.Println(country, "首都是", countryCapitalMap [ country])
    }
vue 常用
@keyup.enter="searchList" 
clearable

正文完
 0