object htmlencode2(object str)
{
object result;
object l;
if (isNULL(str)) {
htmlencode2 = "";
return null;
}
l = len(str);
result = "";
object i;
for (int i = 1; i <= l; i++) {
if (mid(str, i, 1) == chr(13)) {
result = result + "<br>";
} else if (mid(str, i, 1) == chr(34)) {
result = result + """;
} else if (mid(str, i, 1) == "&") {
result = result + "&";
} else if (mid(str, i, 1) == chr(32)) {
if (i + 1 <= l & i - 1 > 0) {
if (mid(str, i + 1, 1) == chr(32) | mid(str, i + 1, 1) == chr(9) | mid(str, i - 1, 1) == chr(32) | mid(str, i - 1, 1) == chr(9)) {
result = result + " ";
} else {
result = result + " ";
}
} else {
result = result + " ";
}
} else if (mid(str, i, 1) == chr(9)) {
result = result + " ";
} else {
result = result + mid(str, i, 1);
}
}
htmlencode2 = result;
}
{
object result;
object l;
if (isNULL(str)) {
htmlencode2 = "";
return null;
}
l = len(str);
result = "";
object i;
for (int i = 1; i <= l; i++) {
if (mid(str, i, 1) == chr(13)) {
result = result + "<br>";
} else if (mid(str, i, 1) == chr(34)) {
result = result + """;
} else if (mid(str, i, 1) == "&") {
result = result + "&";
} else if (mid(str, i, 1) == chr(32)) {
if (i + 1 <= l & i - 1 > 0) {
if (mid(str, i + 1, 1) == chr(32) | mid(str, i + 1, 1) == chr(9) | mid(str, i - 1, 1) == chr(32) | mid(str, i - 1, 1) == chr(9)) {
result = result + " ";
} else {
result = result + " ";
}
} else {
result = result + " ";
}
} else if (mid(str, i, 1) == chr(9)) {
result = result + " ";
} else {
result = result + mid(str, i, 1);
}
}
htmlencode2 = result;
}
解决方案 »
- C#关于多用户的问题(例如论坛、新闻系统)?
- 二维数组 无法封送处理
- 在.net中这样做合适吗?
- VS2008的Project设置中有一个Target Framework是什么作用?
- 急:关于 DES 加密解密的问题。
- 请问高手如何在REMOTING的SERVER 获得所有客户端连接的代理链?
- 请教如何在WINFORM的DATAGRID的单元格里添加CHECKBOX或者其他控件???谢谢。。急。。
- 文本文件的读写问题
- C#中使用ExecuteNonQuery()出现报错!!!在线等待!!!!急!!!!!
- 哪儿有IL的资料啊?英文也行呀?
- 急!(高分求助!)请问如何实现文件传输?(最好有源码)
- C#怎样访问Access数据库中的OLE对象类型-----急,请高手帮忙
Server.HtmlDecode();这两个函数能实现你的要求。
{
string result;
int l;
if (str == null)
{
return "";
}
l=str.Length;
result="";
int i;
for (i=0;i<=l;i++)
{
switch (str.Substring(i,1))
{
case "\r":
result=result+"<br>";
break;
case "\"":
result=result+""";
break;
case "&":
result=result+"&";
break;
case " ":
if (i+1<=l && i-1>0)
{
if (str.Substring(i+1,1)==" " || str.Substring(i+1,1)=="\t" || str.Substring(i-1,1)==" " || str.Substring(i-1,1)=="\t")
result=result+" ";
else
result=result+" ";
}
else
result=result+" ";
break;
case "\t":
result=result+" ";
break;
default:
result=str.Substring(i,1);
break;
}
}
return result;
}