本文整理汇总了C#中System.IO.StringReader.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.Substring方法的具体用法?C# StringReader.Substring怎么用?C# StringReader.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringReader
的用法示例。
在下文中一共展示了StringReader.Substring方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TraceEvent
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
{
if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
{
return;
}
var client = new SmtpClient(Settings.Default.SmtpServer)
{
Credentials = new NetworkCredential(Settings.Default.SmtpUsername, Settings.Default.SmtpPassword),
EnableSsl = true
};
var body = string.Format(format, args);
var firstLine = new StringReader(body).ReadLine();
if (firstLine.Length > 100)
{
firstLine = firstLine.Substring(0, 97).Trim() + "...";
}
var msg = new MailMessage
{
From = new MailAddress(Settings.Default.NotificationFrom, "FitBot"),
To = {Settings.Default.NotificationTo},
Subject = $"{eventType} - {firstLine}",
Body = body
};
client.Send(msg);
}
示例2: GetTypeahead
public virtual async Task<ActionResult> GetTypeahead(string q)
{
// Query the search service
var results = await SearchService.Search(new SearchFilter()
{
SearchTerm = q, /* For typeahead we want wildcard matching */
IncludePrerelease = true,
Take = 5
});
// Return the results formatted as JSON
return Json(results.Data.AsEnumerable().Select(p => {
var summary = p.Summary ?? p.Description;
// Truncate to a single line
summary = new StringReader(summary).ReadLine();
if (summary.Length > 350)
{
summary = summary.Substring(0, 350) + "...";
}
return new {
Key = p.Key,
Id = p.PackageRegistration.Id,
Title = p.Title,
Version = p.NormalizedVersion,
Summary = summary
};
}), JsonRequestBehavior.AllowGet);
}