本文整理汇总了C#中System.IO.StringWriter.TrimEnd方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.TrimEnd方法的具体用法?C# StringWriter.TrimEnd怎么用?C# StringWriter.TrimEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringWriter
的用法示例。
在下文中一共展示了StringWriter.TrimEnd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToHeaderString
public static string ToHeaderString(this IList<EmailContact> contacts)
{
if (contacts.Count == 0) {
return string.Empty;
}
using (var sw = new StringWriter()) {
foreach (var contact in contacts) {
sw.WriteFormat("{0} <{1}>,", contact.Name, contact.Address);
}
sw.TrimEnd(',');
return sw.ToString();
}
}
示例2: FormatHeaderFieldsCommand
private static string FormatHeaderFieldsCommand(IEnumerable<string> headers)
{
using (var sw = new StringWriter()) {
sw.Write("HEADER.FIELDS (");
foreach (var header in headers) {
sw.Write(header);
sw.Write(Characters.Space);
}
sw.TrimEnd(Characters.Space);
sw.Write(")");
return sw.ToString();
}
}
示例3: MakeRequest
public WebResponse MakeRequest()
{
var requestParams = CreateOAuthRequestParams();
if (_sign) {
var signature = OAuthSignature.Create(this, requestParams);
requestParams.Add(OAuthParameters.OAuthSignature, signature);
}
string url;
using (var sw = new StringWriter()) {
sw.Write(RequestEndpoint.AbsoluteUri);
sw.Write("?");
var sorted = new SortedDictionary<string, string>();
foreach (var p in Parameters) {
sorted.Add(p.Key, p.Value);
}
foreach (var p in requestParams) {
sorted.Add(p.Key, p.Value);
}
foreach (var p in sorted) {
sw.Write("{0}={1}", p.Key, p.Key == OAuthParameters.OAuthVerifier
? HttpEncoder.UrlEncode(p.Value) : p.Value);
sw.Write("&");
}
// if params have been written the last item will be a '&' else it will be a '?'.
sw.TrimEnd('&');
sw.TrimEnd('?');
url = sw.ToString();
}
var request = (HttpWebRequest) WebRequest.Create(url);
request.Accept = "*/*";
request.Method = "GET";
request.Headers.Add(HttpRequestHeader.Authorization, "OAuth");
return request.GetResponse();
}
示例4: GetAuthorizationUri
public Uri GetAuthorizationUri()
{
string url;
using (var sw = new StringWriter()) {
sw.Write(RequestEndpoint.AbsoluteUri);
if (Parameters.Count > 0) {
sw.Write("?");
foreach (var p in Parameters) {
sw.WriteFormat("{0}={1}&", p.Key, p.Value);
}
sw.TrimEnd('&');
}
url = sw.ToString();
}
var request = (HttpWebRequest) WebRequest.Create(url);
request.Accept = "*/*";
request.Method = "GET";
var response = request.GetResponse();
return response.ResponseUri;
}
示例5: CreateXOAuthKey
public string CreateXOAuthKey()
{
var requestParams = CreateOAuthRequestParams();
if (_sign) {
var signature = OAuthSignature.Create(this, requestParams);
requestParams.Add(OAuthParameters.OAuthSignature, signature);
}
string token;
using (var sw = new StringWriter()) {
sw.Write("GET ");
sw.Write(RequestEndpoint.AbsoluteUri);
sw.Write(Characters.Space);
var sorted = new SortedDictionary<string, string>();
foreach (var p in Parameters) {
sorted.Add(p.Key, p.Value);
}
foreach (var p in requestParams) {
sorted.Add(p.Key, p.Value);
}
foreach (var p in sorted) {
sw.WriteFormat("{0}=\"{1}\",", p.Key, p.Value);
}
sw.TrimEnd(',');
token = sw.ToString();
}
var bytes = Encoding.ASCII.GetBytes(token);
return Convert.ToBase64String(bytes);
}
示例6: NormalizeRequestParameters
private static IEnumerable<char> NormalizeRequestParameters(IEnumerable<KeyValuePair<string, string>> @params)
{
using (var sw = new StringWriter()) {
foreach (var pair in @params) {
sw.Write(pair.Key);
sw.Write("=");
sw.Write(pair.Value);
sw.Write("&");
}
sw.TrimEnd('&');
return sw.ToString();
}
}