写个函数给你参考一下:
<!-- Begin
function replaceChars(entry)
{
out = new Array("全角的空格","全角的字符");//可以有多个
add = new Array("你要替换的东西","你要替换的东西2");temp = "" + entry; // temporary holder
for (i=0;i<90;i++)
{
while (temp.indexOf(out[i])>-1)
{
pos= temp.indexOf(out[i]);
temp = "" + (temp.substring(0, pos) + add[i] +
temp.substring((pos + out[i].length), temp.length));
}
}
document.form1.Body.value = temp;//你要进行处理的输入域,可以是form2,3之类的。
}// End -->
<!-- Begin
function replaceChars(entry)
{
out = new Array("全角的空格","全角的字符");//可以有多个
add = new Array("你要替换的东西","你要替换的东西2");temp = "" + entry; // temporary holder
for (i=0;i<90;i++)
{
while (temp.indexOf(out[i])>-1)
{
pos= temp.indexOf(out[i]);
temp = "" + (temp.substring(0, pos) + add[i] +
temp.substring((pos + out[i].length), temp.length));
}
}
document.form1.Body.value = temp;//你要进行处理的输入域,可以是form2,3之类的。
}// End -->
例如我读入一个string值为"-- start flag --"在'-'和'start'之间是个全角空格,读入这个string后跟踪看到的string = "--$B!!(Bstart flag --",全角空格已经是乱码了,对应的具体的string的组成是char[23]=
--\u001B$B!!\u001B(Bstart flag --
也就是说
"--$B!!(Bstart flag --"里显示不出来的方框变成了\u001B,其他可显示的字符就都照原样显示了,所以原来的全角空格,现在已经不是全角空格了,而是变成了其它的字符,所以简单地替换是不成功的。我后来又用javax.mail.internet.MimeUtility:
MimeUtility.decodeText("这个string");//先对string解码
再用replace替换,还是不行~~~
不晓得怎么办了:(
不过明天代码就release了,看来只能把这个问题算作限制事项写到用户手册了