查找字符串
//js
var str="hello"
str.indexOf("he");
//indexOf() 方法返回指定值在字符串对象中首次出现的位置。从fromIndex位置开始查找 如果不存在 则返回-1
//golang
strings.Contains("widuu", "wi")
//php
echo strpos("You love php, I love php too!","php");
字符串分割
//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
字符串替换
//Golang
msg = strings.Replace(msg, "<script>", "不要想xss", -1)
//js
str.replace(/需要替换的字符串/g,"新字符串")
类型转换
//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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。