Posted on 2008-06-04 17:19
G_G 閱讀(235)
評論(0) 編輯 收藏 所屬分類:
javaGeneral
????
public
?
static
?String?filter(String?input)?{
????????
if
?(input?
==
?
null
)?{
????????????
return
?
null
;
????????}
????????StringReader?stringReader?
=
?
new
?StringReader(input);
????????BufferedReader?reader?
=
?
new
?BufferedReader(stringReader);
????????StringBuffer?ret?
=
?
new
?StringBuffer(input.length()?
+
?
200
);
//
?add?more?room?to?the?result?String
????????String?line?
=
?
null
;
????????
try
?{
??? ?? ?? ? //換行后添加<br/>
????????????
while
?((line?
=
?reader.readLine())?
!=
?
null
)?{
??? ?? ?? ?? ?? //wap 對 <? >的替換
????????????????ret.append(line.replaceAll(
"
<
"
,?
"
<
"
).replaceAll(
"
>
"
,?
"
>
"
).
replaceAll(
"&",?"&"
)
).append(
"
<br/>
"
);
????????????}
//
while
????????????
//
如果是最后一行
????????}?
catch
?(IOException?ex)?{}
???????
return
?
"
"
+
ret.toString()?;
????}
????