1、Java的substring
public String substring(int beginIndex) 或 public String substring(int beginIndex, int endIndex) beginIndex -- 起始索引(包括), 索引从 0 开始。 endIndex -- 结束索引(不包括)。 String s = "thisname"; String s1 = s.substring(2);// isname String s2 = s.substring(2, 5);//isn
2、js的substring
string.substring(from, to) from 必需。一个非负的整数,规定要提取的子串的第一个字符在 string Object 中的位置。 to 可选。一个非负的整数,比要提取的子串的最后一个字符在 string Object 中的位置多 1。 如果省略该参数,那么返回的子串会一直到字符串的结尾。 var str="Hello world!"; document.write(str.substring(2)+"
"); document.write(str.substring(2,8)); 结果: llo world! llo wo
3、MySQL的substring
SUBSTRING(s, start, length)
从字符串 s 的 start 位置截取长度为 length 的子字符串
从字符串 RUNOOB 中的第 2 个位置截取 3个 字符:
SELECT SUBSTRING("MySQL", 2, 3) AS ExtractString; -- ySQ
总结:
Java与js按索引算,包含开始不包含结束。MySQL按位置算,截取长度



