当我使用字符串构建器追加字符串时插入一个附加字符,为什么?

时间:2014-01-10 05:51:22

标签: asp.net stringbuilder

我使用以下代码

 body.Append("grant_type=password&");
    body.Append("client_id="+clientID +"&");
    body.Append("client_secret="+clientSecret+"&");
    body.Append("username="+username+"&");
    body.Append("password="+password);
    body.Append(security_token);

但是在password和security_token之间插入一个额外的字符“1”。请注意,'body'是一个StringBuilder对象。

更新

当密码中包含数字时会发生此问题。

例如

password ="enterinside";
security_token ="1bbssddffgg";

然后输出为“enterinside1bbssddffgg”

但如果密码=“enterinside999”      security_token =“1bbssddffgg” 然后输出为“enterinside1999 bbssddffgg”。

1 个答案:

答案 0 :(得分:0)

你可以简单地做AppendFormat

body.AppendFormat("password={0}1",password);
body.Append(security_token);

http://www.dotnetperls.com/appendformat

http://msdn.microsoft.com/en-us/library/hdekwk0b(v=vs.110).aspx