• 主页
  • ASP
  • .NET Framework
  • Web Services
  • VB
  • VC
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • LINQ

如何把"a b c"转换为"a%20b%20c%20"?

hproof 2003-03-30 11:13:49
抱歉,我没有vs70,根本不知道里面有哪些类哪些函数.
...全文
31 点赞 收藏 13
写回复
13 条回复
goody9807 2003年04月07日
str=str.replace(" ","%20")
回复 点赞
xupc 2003年04月07日
Server.UrlEncode()
回复 点赞
zs1024cn 2003年04月07日
你是在服务器端还是在Browse端?
在Browse:
<script language=javascript>
form1.action="abc.asp?parm=" + escape("a b c....");
</script>

在Server:
用Server.UrlEncode("a b c ...") (asp也支持)
回复 点赞
xumahua 2003年04月07日
UP
回复 点赞
timmy3310 2003年04月07日
有这么复杂吗?

这样就行了:

string encodeValue = HttpContext.Current.Server.UrlEncode( "a b c" );

这是.Net内置的方法,转换Url参数字符串的,它不仅仅把" "转成"%20",它会把所有的都转换,不过不影响你使用

回复 点赞
houjianxun 2003年04月07日
按二楼的方法做

对 字符串进行URL编码,就可以了
回复 点赞
hproof 2003年04月07日
using System;

namespace DataAccess
{
/// <summary>
///
/// </summary>
struct StringTable
{
public String code;
public String str;
public String htmlcode;
public StringTable(String c, String s, String h){
code=c; str=s; htmlcode=h;
}
};
public class MyConvert
{
static StringTable[] table =
{
new StringTable ("_z", "_", "_"), // _
new StringTable ("_a", "&" , "&"), // &
new StringTable ("_b", "\"", """), // "
new StringTable ("_c", "'", "'"), // '
new StringTable ("_d", "<", "<"), // <
new StringTable ("_e", ">", ">"), // >
new StringTable ("_f", " ", " "), // [ ]
new StringTable ("_g", "?", "?") // ?
};


static public String StrToCode(String str)
{
for(int i=0; i<table.Length; i++)
{
str = str.Replace (table[i].str , table[i].code );
}
return str;
}

static public String CodeToStr(String str)
{
for(int i=table.Length -1; i>=0; i--)
{
str = str.Replace (table[i].code , table[i].str );
}
return str;
}

static public String CodeToHtmlCode(String str)
{
for(int i=table.Length -1; i>=0; i--)
{
str = str.Replace (table[i].code , table[i].htmlcode );
}
return str;
}
static public String HtmlToHtmlCode(String str)
{
for(int i=0; i<table.Length ; i++)
{
str = str.Replace (table[i].str , table[i].htmlcode );
}
return str;
}
static public String HtmlCodeToHtml(String str)
{
for(int i=table.Length -1; i>=0; i--)
{
str = str.Replace (table[i].htmlcode , table[i].str );
}
return str;
}
}
}
回复 点赞
blackant2 2003年03月30日
使用urlencode方法就可以了
然后你还有什么特殊要求再替换吧
回复 点赞
Lovemartyr 2003年03月30日
贴一个我的ubb函数给你吧.

Public Function UBBContent(strContent As String)

strContent = strContent.Replace("&","&")
strContent = strContent.Replace("<","<")
strContent = strContent.Replace(">",">")
strContent = strContent.Replace(chr(34),""")
strContent = strContent.Replace(chr(39),"'")
strContent = strContent.Replace(chr(10)+chr(10),"<p></p>")
strContent = strContent.Replace(chr(10),"<br>")
strContent = strContent.Replace(chr(32)," ")
strContent = strContent.Replace(chr(32)," ")
strContent = Regex.Replace(strContent,"\[url=(?<x>[^\]]*)\](?<y>[^\]]*)\[/url\]","<font color='" + Forum_Template_Particular + "'>↓</font> <a href=$1 target=_blank>$2</a>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[url\](?<x>[^\]]*)\[/url\]","<a href=$1 target=_blank><font color='" + Forum_Template_Particular + "'>↓</font> $1</a>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\]*)\](?<y>[^\]]*)\[/email\]","<a href=$1>$2</a>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[email\](?<x>[^\]]*)\[/email\]","<a href=$1>$1</a>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[swf=(?<x>[^\]]*),(?<y>[^\]]*)\](?<z>[^\]]*)\[/swf]","<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=""$1"" height=""$2""><PARAM NAME=movie VALUE=""$3""><PARAM NAME=quality VALUE=high><embed src=""$3"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=""$1"" height=""$2"">$3</embed></OBJECT>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[img](?<x>[^\]]*)\[/img]","<IMG SRC=""$1"" border=0>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[mp=(?<x>[^\]]*),(?<y>[^\]]*)\](?<z>[^\]]*)\[/mp]","<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=""$1"" height=""$1"" ><param name=ShowStatusBar value=-1><param name=Filename value=""$3""><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=""$3"" width=""$1"" height=""$2""></embed></object>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[rm=(?<x>[^\]]*),(?<y>[^\]]*)\](?<z>[^\]]*)\[/rm]","<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=""$1"" height=""$2""><PARAM NAME=SRC VALUE=""$3""><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=""$1""><PARAM NAME=SRC VALUE=""$3""><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[color=(?<x>[^\]]*)\](?<y>[^\]]*)\[/color\]","<font color=$1>$2</font>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[face=(?<x>[^\]]*)\](?<y>[^\]]*)\[/face\]","<font face=$1>$2</font>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[size=1\](?<x>[^\]]*)\[/size\]","<font size=1>$1</font>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[size=2\](?<x>[^\]]*)\[/size\]","<font size=2>$1</font>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[size=3\](?<x>[^\]]*)\[/size\]","<font size=3>$1</font>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[size=4\](?<x>[^\]]*)\[/size\]","<font size=4>$1</font>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[align=(?<x>[^\]]*)\](?<y>[^\]]*)\[/align\]","<align=$1>$2</align>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[fly](?<x>[^\]]*)\[/fly]","<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[move](?<x>[^\]]*)\[/move]","<marquee scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[glow=(?<x>[^\]]*),(?<y>[^\]]*),(?<z>[^\]]*)\](?<w>[^\]]*)\[/glow\]","<table width=$1 style='filter:glow(color=$2, strength=$3)'>$4</table>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[shadow=(?<x>[^\]]*),(?<y>[^\]]*),(?<z>[^\]]*)\](?<w>[^\]]*)\[/shadow\]","<table width=$1 style='filter:shadow(color=$2, strength=$3)'>$4</table>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[b\](?<x>[^\]]*)\[/b\]","<b>$1</b>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[i\](?<x>[^\]]*)\[/i\]","<i>$1</i>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[u\](?<x>[^\]]*)\[/u\]","<u>$1</u>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[list\](?<x>[^\]]*)\[/list\]","<ul>$1</ul>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[list=1\](?<x>[^\]]*)\[/list\]","<ol type=1>$1</ol id=1>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[list=a\](?<x>[^\]]*)\[/list\]","<ol type=a>$1</ol id=a>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\[\*\](?<x>[^\]]*)\[/\*\]","<li>$1</li>",RegexOptions.IgnoreCase)
strContent = Regex.Replace(strContent,"\
引用
(?<x>.*)\
","<font color='" + Forum_Template_Navigation + "'>引用:<br/>-----------------------------------<br/>$1<br/>-----------------------------------</font>",RegexOptions.IgnoreCase)

UBBContent = strContent

End Function
回复 点赞
Lovemartyr 2003年03月30日
str=str.replace(" ","%20")
or
str=str.replace(chr(32),"%20")

str为字符串
回复 点赞
ASPXman 2003年03月30日
Dim urlabc As string
urlabc="a b c"
urlabc=Server.UrlEncode(urlabc)
回复 点赞
hproof 2003年03月30日
除了空格外,当然还包括< > / " ]]> & 等乱七八糟的。
回复 点赞
孟子E章 2003年03月30日
<script>
alert(escape("a b c"))
</script>
回复 点赞
发动态
发帖子
.NET技术社区
创建于2007-09-28

4.9w+

社区成员

66.8w+

社区内容

.NET技术交流专区
社区公告
暂无公告