我是想把URL中某部分的非字母和数字的符号/汉字转换成UTF8码,比如:
LoginMUser=904621&LoginMPass=hgjkkghjk&image2.x=24&image2.y=11
如果我想让LoginMUser为aaa+[回车],那么这么回车就要转换成UTF8码,就是
LoginMUser=aaa%0D%0A,如果LoginMUser为aa+.话就是LoginMUser=aa%2E,所以我要在URL中分段寻找‘=’和‘&’之间的字符串(字符穿中可能有'='但是一定没有'&'),然后把需要转换的部分转换成UTF8码,然后把转换成的UTF8码和原来的部分连起来形成新的字符串输出,然后计算字节数长度。
我写的:
[code]
private void code_TextChanged(object sender, System.EventArgs e)
{
encode.Text="";
string str=code.Text;
byte[] bytStr =Encoding.Default.GetBytes(str);
int byte_len = bytStr.Length;
code_len.Text=byte_len.ToString();
bool flag_1=false; //=号出现标志
bool flag_2=false; //&号出现标志
int len=str.Length;
string temp_str="";
for(int i=0;i<len;i++)
{
string temp=str[i].ToString();
if(!flag_1)
{
if(temp!="=")
encode.Text=encode.Text+temp;
else 
{
flag_1=!flag_1;
encode.Text=encode.Text+"=";
}
}
else
{
if(!flag_2)
{
if(temp!="&")
{
byte[] byte_temp;
UTF8Encoding dd=new UTF8Encoding();
byte_temp=dd.GetBytes(temp);
encode.Text=encode.Text+byte_temp.ToString();
}
else
{
encode.Text=encode.Text+"&";
flag_1=!flag_1;
}
} }
} }
[/code]
但是结果中它把需要转换的部分全都输出成System.Byte[],该怎么写啊