java,php,JavaScript判断字符串中是否有空格
2009-07-21 文章来源:互联网 浏览次数:1118
- class Havespace{
- public static void main(String args[]){
- String txt="abc def";
- boolean mat = txt.matches("^(\\s|.*\\s+.*)$");
- if(mat){
- System.out.println("have space");
- }else{
- System.out.println("no space");
- }
- }
- }
- $str = "abc def";
- $strArr = explode(" ", $str);
- if(count($strArr)!=1){
- echo "have space";
- }else{
- echo "no space";
- }
- var s = "abcab cdaaa";
- ss = s.split(" ");
- if(ss.length!=1){
- alert("have space");
- }else{
- alert("no space");
- }

文章评论(查看全部)