javaÕýÔò±í´ïʽ
javaÕýÔò±í´ïʽͨ¹ýjava.util.regex°üϵÄPatternÀàÓëMatcherÀàʵÏÖ(½¨ÒéÔÚÔĶÁ±¾ÎÄʱ,´ò¿ªjava APIÎĵµ,µ±½éÉܵ½Äĸö·½·¨Ê±,²é¿´java APIÖеķ½·¨ËµÃ÷,Ч¹û»á¸ü¼Ñ).
PatternÀàÓÃÓÚ´´½¨Ò»¸öÕýÔò±í´ïʽ,Ò²¿ÉÒÔ˵´´½¨Ò»¸öÆ¥Åäģʽ,ËüµÄ¹¹Ôì·½·¨ÊÇ˽ÓеÄ,²»¿ÉÒÔÖ±½Ó´´½¨,µ«¿ÉÒÔͨ¹ýPattern.complie(String regex)¼òµ¥¹¤³§·½·¨´´½¨Ò»¸öÕýÔò±í´ïʽ,
Java´úÂëʾÀý:
Pattern p=Pattern.compile("\\w+");
p.pattern();//·µ»Ø \w+
pattern() ·µ»ØÕýÔò±í´ïʽµÄ×Ö·û´®ÐÎʽ,Æäʵ¾ÍÊÇ·µ»ØPattern.complile(String regex)µÄregex²ÎÊý
1.Pattern.split(CharSequence input)
PatternÓÐÒ»¸ösplit(CharSequence input)·½·¨,ÓÃÓÚ·Ö¸ô×Ö·û´®,²¢·µ»ØÒ»¸öString[],ÎÒ²ÂString.split(String regex)¾ÍÊÇͨ¹ýPattern.split(CharSequence input)À´ÊµÏÖµÄ.
Java´úÂëʾÀý:
Pattern p=Pattern.compile("\\d+");
String[] str=p.split("ÎÒµÄQQÊÇ:456456Îҵĵ绰ÊÇ:0532214ÎÒµÄÓÊÏäÊÇ:aaa@aaa.com");
½á¹û:str[0]="ÎÒµÄQQÊÇ:" str[1]="Îҵĵ绰ÊÇ:" str[2]="ÎÒµÄÓÊÏäÊÇ:aaa@aaa.com"
2.Pattern.matcher(String regex,CharSequence input)ÊÇÒ»¸ö¾²Ì¬·½·¨,ÓÃÓÚ¿ìËÙÆ¥Åä×Ö·û´®,¸Ã·½·¨ÊʺÏÓÃÓÚֻƥÅäÒ»´Î,ÇÒÆ¥ÅäÈ«²¿×Ö·û´®.
Java´úÂëʾÀý:
Pattern.matches("\\d+","2223");//·µ»Øtrue
Pattern.matches("\\d+","2223aa");//·µ»Øfalse,ÐèҪƥÅäµ½ËùÓÐ×Ö·û´®²ÅÄÜ·µ»Øtrue,ÕâÀïaa²»ÄÜÆ¥Åäµ½
Pattern.matches("\\d+","22bb23");//·µ»Øfalse,ÐèҪƥÅäµ½ËùÓÐ×Ö·û´®²ÅÄÜ·µ»Øtrue,ÕâÀïbb²»ÄÜÆ¥Åäµ½
3.Pattern.matcher(CharSequence input)
˵ÁËÕâô¶à,ÖÕÓÚÂÖµ½MatcherÀàµÇ³¡ÁË,Pattern.matcher(CharSequence input)·µ»ØÒ»¸öMatcher¶ÔÏó.
MatcherÀàµÄ¹¹Ôì·½·¨Ò²ÊÇ˽ÓеÄ,²»ÄÜËæÒâ´´½¨,Ö»ÄÜͨ¹ýPattern.matcher(CharSequence input)·½·¨µÃµ½¸ÃÀàµÄʵÀý.
PatternÀàÖ»ÄÜ×öһЩ¼òµ¥µÄÆ¥Åä²Ù×÷,ÒªÏëµÃµ½¸üÇ¿¸ü±ã½ÝµÄÕýÔòÆ¥Åä²Ù×÷,ÄǾÍÐèÒª½«PatternÓëMatcherÒ»ÆðºÏ×÷.MatcherÀàÌṩÁ˶ÔÕýÔò±í´ïʽµÄ·Ö×éÖ§³Ö,ÒÔ¼°¶ÔÕýÔò±í´ïʽµÄ¶à´ÎÆ¥ÅäÖ§³Ö.
Java´úÂëʾÀý:
Pattern p=Pattern.compile("\\d+");
Matcher m=p.matcher("22bb23");
m.pattern();//·µ»Øp Ò²¾ÍÊÇ·µ»Ø¸ÃMatcher¶ÔÏóÊÇÓÉÄĸöPattern¶ÔÏóµÄ´´½¨µÄ
4.Matcher.matches() / Matcher.lookingAt() / Matcher.find()
MatcherÀàÌṩÈý¸öÆ¥Åä²Ù×÷·½·¨,Èý¸
Ïà¹ØÎĵµ£º
2009Äê×îºóÒ»²©£º¹ØÓÚ Java ÖжÔÏóµÄ¸´ÖÆ
Java Öеĸ³Öµ²Ù×÷·ûÓë C++ ÖеIJ»Ò»Ñù¡£ÔÚ C++ ÖУ¬ÕâÌõÓï¾ä£ºbc2 = bc1;½«Ò»¸öÃûΪ bc1 µÄ¶ÔÏóµÄËùÓÐÊý¾Ý¶¼¿½±´µ½ÃûΪ bc2 µÄ¶ÔÏóÖС£Ò²¾ÍÊÇ˵ÕâÌõÓï¾äÖ´Ðк󣬳ÌÐòÖÐÓÐÁ½¸öº¬ÓÐÏàͬÊý¾ÝµÄ¶ÔÏó¡£È»¶øÔÚ Java ÖУ¬ÕâÌõÏàͬµÄ¸³ÖµÓï¾ä ......
¿´µ½Ò»ÆªÎÄÕ¸оõºÜºÃ£¬×ª¹ýÀ´ÁË... http://bbs.chinaitlab.com/thread-167286-1-2.html
Äã¾õµÃ×Ô¼ºÊÇÒ»¸öJavaר¼ÒÂð£¿ÊÇ·ñ¿Ï¶¨×Ô¼ºÒѾȫÃæÕÆÎÕÁËJavaµÄÒì³£´¦Àí»úÖÆ£¿ÔÚÏÂÃæÕâ¶Î´úÂëÖУ¬ÄãÄܹ»Ñ¸ËÙÕÒ³öÒì³£´¦ÀíµÄÁù¸öÎÊÌâÂð£¿
1 OutputStreamWri ......
platform ['plætfɔ:m] n.ƽ̨
standard edition±ê×¼°æ
enterprise ['entəpraiz] n. ÆóÒµ
bytecode n.×Ö½ÚÂ룬×Ö½Ú´úÂë
verifier n. ¼ìÑé»ú
modifier [‘mɔdifaiə] n.ÐÞÊÎÓï
attribute [‘ætribju:t] vt.(to)°Ñ…¹éÒòÓÚn.ÊôÐÔ£¬ÌØÐÔ
declaration ......
Êý×éÊôÒýÓÃÀàÐÍ£¬Êý×éÐÍÊý¾ÝÊǶÔÏó(object)£¬Êý×éÖеÄÿ¸öÔªËØÏ൱ÓڸöÔÏóµÄ³ÉÔ±±äÁ¿
Êý×éÖеÄÔªËØ¿ÉÒÔÊÇÈκÎÊý¾ÝÀàÐÍ£¬°üÀ¨»ù±¾ÀàÐͺÍÒýÓÃÀàÐÍ
¼ÇסÊý×éÊ×ÏÈ·ÖÅä¿Õ¼äÔÙ¸³Öµ£¡
¶¯Ì¬³õʼ»¯£º¾ÍÊÇÏÈ·ÖÅä¿Õ¼äÔÙ¸³³õÖµ£»
¾²Ì¬³õʼ»¯£º¶¨ÒåÊý×éͬʱ¾ÍΪÊý×éÔªËØ·ÖÅä¿Õ¼ä²¢¸³Öµ¡£
1һάÊý×éµÄÉùÃ÷
һάÊý×éµÄÉùÃ÷£ºtype va ......
´ÓCore Javaµ½Thinking in Java
JavaÊÇÒ»ÖÖ¿çƽ̨¡¢ÃæÏò¶ÔÏ󡢸øÓèÍøÂç¼°Ö§³Ö¶àýÌåµÄ±à³ÌÓïÑÔ£¬²¢¿É²åÈëµ½HTMLÎĵµÖС£
1.ÔÚhtmlÎĵµÖÐÌí¼ÓÁ´½Ó£¬¼´ÔÚ<body>±êÇ©¼ä²åÈëÒÔÏ´úÂ룺
<applet code=ÀàÃû.class width=¿í¶È height=¸ß¶È></applet>
2.·â×°ÊÇÒ»ÖÖ½«´úÂë¼°Æä´¦ÀíµÄÊý¾Ý°ó¶¨ÔÚÒ»Æð± ......