小知识

Posted on 2007-09-25 16:57 angel 阅读(208) 评论(0)  编辑  收藏

1、去左右空格
---左trim----
String s = " abc ";
s = s.replaceAll("^ +", "");

----右trim----
String s = " abc ";
s = s.replaceAll(" +$", "");


2、删除子串 ,例如 :this is a cup 如何从第2个字符开始 删除 4个字符
StringBuffer buff=new StringBuffer("this is a cup ");
  buff.delete(2,4);

3、比较二个日期的大小
var dateStr= '2007-9-26';//格式是写死的就是yyyy-MM-dd  
var dateArr = dateStr.split('-');  
var date = new Date(dateArr[0],dateArr[1],dateArr[2]);  
var date1 = new Date();  
alert(date>=date1?'大':'小');


只有注册用户登录后才能发表评论。


网站导航:
 

Copyright © angel