java×Ö·û´®Ìæ»»×Ö·û´®ÊµÀý,¶Ôreplace·½·¨µÄÖØд
package com.citycollege.stw;
public class testreplace {
public static final String replace( String line, String oldString, String newString )
{
if (line == null)
{
return null;
}
int i=0;
if ( ( i=line.indexOf( oldString, i ) ) >= 0 )
{
char [] line2 = line.toCharArray(); //×Ö·û´®·ÅÈëÊý×é
char [] newString2 = newString.toCharArray(); //ÒªÌæ»»µÄ×Ö·û´®
int oLength = oldString.length(); //±»Ìæ»»µÄ×Ö·û´®µÄ³¤¶È
StringBuffer buf = new StringBuffer(line2.length);
buf.append(line2, 0, i).append(newString2);
i += oLength;
int j = i;
while( ( i=line.indexOf( oldString, i ) ) > 0 )
{
buf.append(line2, j, i-j).append(newString2);
i += oLength;
j = i;
}
buf.append(line2, j, line2.length - j);
return buf.toString();
}
return line;
}
public static void main(String args[]){
String s="I OK OK best OK" +
"She OK OK BESTU OK";
String s1=replace(s,"OK","hello");
System.out.println(s1);
Ïà¹ØÎĵµ£º
Ä¿Ç°ºÜ¶àѧÉúÃæÁÙמÍÒµµÄÎÊÌ⣬µ±È»£¬ÏñÎÒÒ»ÑùµÄ¸Õ±ÏÒµµÄ´óѧÉúÒ²²»ÀýÍâ¡£´óѧʱѧµÄÊǼÆËã»úרҵµÄ£¬´óѧËÄÄê×ÜÒÔΪ°Ñרҵ¿ÎѧºÃ£¬±ÏÒµÁ˾ͿÉÒÔÕÒµ½Ò»·Ý²»´íµÄ¹¤×÷¡£
¿ÉÊǼ¸¸öÔÂÃæÊԵĽÓÁ¬Åö±Ú£¬Ê¹ÎҸе½´óѧÀïѧµÄרҵ֪ʶÀíÂÛÐÔÌ«Ç¿£¬Êµ¼Ê ......
¡¾×ª¡¿JavaÖеÄλÔËËã·û
Ô×÷ÕߣºRosen Jiang ³ö´¦£ºhttp://www.blogjava.net/rosen
ÒÆλÔËËã·û
°üÀ¨£º
“>> ÓÒÒÆ”£»“<< ×óÒÆ”£»“>>> ÎÞ·ûºÅÓÒÒÆ”
Àý×Ó£º
-5>>3=-1
1111 1111 1111 1111 1111 1111 1111 ......
ÔÚJava5ÖÐÌṩÁ˱䳤²ÎÊý£¬Ò²¾ÍÊÇÔÚ·½·¨¶¨ÒåÖпÉÒÔʹÓøöÊý²»È·¶¨µÄ²ÎÊý£¬¶ÔÓÚͬһ·½·¨¿ÉÒÔʹÓò»Í¬¸öÊýµÄ²ÎÊýµ÷Óã¬ÀýÈ磺print("hello");print("hello","lisi");print("hello","ÕÅÈý");ÏÂÃæ½éÉÜÈçºÎ¶¨Òå¿É±ä³¤²ÎÊýÒÔ¼°ÈçºÎʹÓÿɱ䳤²ÎÊý¡£
1¡¢¿É±ä³¤²ÎÊý·½·¨µÄ¶¨Òå
ʹÓÃ...±íʾ¿É±ä³¤²ÎÊý£¬ÀýÈç
print(String... args ......
http://xxw8393.blog.163.com/blog/static/3725683420091023535411/
Java µÄ³öÏÖ¸ø´ó¼Ò¿ª·¢´øÀ´µÄ¼«´óµÄ·½±ã¡£µ«ÊÇ£¬Èç¹ûÎÒÃÇÓдóÁ¿ÔÓеľ¹ý¹ã·º²âÊԵķÇJava´úÂ룬½«ËüÃÇÈ«²¿ÓÃJavaÀ´ÖØд£¬¿ÖÅ»á´øÀ´¾Þ´óµÄ¹¤×÷Á¿ºÍ³¤ÆڵIJâÊÔ£»Èç¹ûÎÒÃǵÄÓ¦ÓÃÖÐÐèÒª·ÃÎʵ½Ìض¨µÄÉ豸£¬ÉõÖÁÊǽö·ûºÏ¹«Ë¾ÄÚ²¿ÐÅÏ¢½»»¥¹æ·¶µÄÉ豸 ......
¡¡¡¡¶ÔÏóÐòÁл¯ºÍ·´ÐòÁл¯µÄ×÷ÓÃÊÇʲô£¬Ò»Ö±²»ÖªµÀ£¬¿´¿´ÏÂÃæµÄ½éÉÜÁ˽âÁËһЩ¡£
¡¡¡¡ÎÒÃǶ¼ÖªµÀ£¬µ±ÎÒÃÇnewÒ»¸ö¶ÔÏóµÄʱºò£¬Java¾Í»áÔÚÄÚ´æÖд´½¨Ò»¸öÏàÓ¦µÄ¶ÔÏó¹©ÎÒÃǺóÐøʹÓá£Èç¹ûÎÒÃÇ°ÑÕâ¸öJava³ÌÐò¹ØµôµÄ»°£¬ÄÇôÕâ¸ö¶ÔÏóÒ²¾ÍËæ×ÅÎÒÃdzÌÐòµÄ¹Ø±Õ¶øÏûʧ£¬ÈçºÎ²ÅÄÜÔÚÕâÖÖÇé¿öϼÌÐø±£´æÕâ¸ö¶ÔÏóÄØ£¿Õâ¾ÍÊÇJavaÐòÁл¯Ò ......