java/js 分割 java/js翻转
js分割:
var s='我1234567890我1234567890我1234567890我1234567890我1234567890我1234567890',
reg=/.{4}/g,
rs=s.match(reg);
rs.push(s.substring(rs.join('').length));
alert(rs)
java分割:
public static String[] split(String msg, int num) {
num = num + 1;
int len = msg.length();
if (len <= num)
return new String[] {msg};
int count = len / (num - 1);
count += len > (num - 1) * count ? 1 : 0; //这里应该值得注意
String[] result = new String[count];
int pos = 0;
int splitLen = num-1;
for (int i = 0; i < count; i++) {
if (i == count - 1)
splitLen = len - pos;
result[i] = msg.substring(pos, pos+ splitLen);
pos += splitLen;
}
return result;
}
js翻转:
var testString = "1234567爱上8.。";
var testString=testString.split("").reverse().join("");
java翻转
public void convertStr(String str){
//将String
对象转换为可改变的StringBuffer类对象
//然后调用StringBuffer类的reverse()方法实现反转
String strReverse=new
StringBuffer(str).reverse().toString();
System.out.println(strReverse);
}