语法备忘
创建一个表格
一个简单的表格是这么创建的:
语言 | Swift | java | js | php |
---|---|---|---|---|
数组创建 | x={} | x=array() | ||
数组长度 | x.size() | x.length | count($x) | |
数组包含 | x | in_array($y, $x) | ||
数组查找 | x.indexOf() | in_array($y, $x) | ||
数组删除元素 | x.splice() | |||
数组栈入 | x.push() | array_push($x, $y) | ||
数组栈出 | x.pop() | array_pop($x) | ||
字符串创建 | new String() | x.length | strlen($x) | |
字符串长度 | x.length() | x.length | strlen($x) | |
字符串分隔 | x.split(“seg”) | x.split(“seg”) | explode(“seg”,$x) | |
字符串查找 | x.indexOf("") | strpos($x, $y) | ||
字符串删除 | ||||
字符串替换 | x.replace() | str_replace($ str_old,$ str_new, $ x) | ||
字符串拼接 | x+y | x.y | ||
字符串取字符 | x.charAt() | |||
字符串取子串 | x.slice(idx1,idx2) | |||
字符串取子串 | x.substring(idx1,idx2) | mb_substr($ x,$ idx1,lenth) | ||
字符串修剪 | x.trim() | rtrim($x) | ||
字符串匹配 | x.match() |
js的replace,如果不使用REG,只能替换第一个。
示例:
var reg = new RegExp(“line-height:[1234567890]+%”, “g”)
data1 = data1.replace(reg,“line-height:300%”);
PHP 多字节处理:
mb_convert_encoding(
x
,
′
u
t
f
−
8
′
)
;
m
b
s
t
r
p
o
s
(
x, 'utf-8'); mb_strpos(
x,′utf−8′);mbstrpos(x, $y);
js 类型转换:
str2num: parseInt(str)
num2str: num.toString()