本文整理汇总了C#中StringBuilder.AppendLine方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendLine方法的具体用法?C# StringBuilder.AppendLine怎么用?C# StringBuilder.AppendLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.AppendLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
#if DEBUG
Console.SetIn(new System.IO.StreamReader(@"../../test.020.in.txt"));
Debug.Listeners.Add(new ConsoleTraceListener());
#endif
Stopwatch sw = new Stopwatch();
sw.Start();
StringBuilder sb = new StringBuilder();
int lines = int.Parse(Console.ReadLine());
for (int i = 0; i < lines; i++)
{
string line = Console.ReadLine();
bool isValid = Validate(line);
if (isValid)
{
sb.AppendLine("VALID");
}
else
{
sb.AppendLine("INVALID");
}
}
sw.Stop();
Console.Write(sb.ToString());
Debug.WriteLine(sw.Elapsed);
string bla = "asdlj";
}
示例2: BuildExceptionReport
static StringBuilder BuildExceptionReport(Exception e, StringBuilder sb, int d)
{
if (e == null)
return sb;
sb.AppendFormat("Exception of type `{0}`: {1}", e.GetType().FullName, e.Message);
var tle = e as TypeLoadException;
if (tle != null)
{
sb.AppendLine();
Indent(sb, d);
sb.AppendFormat("TypeName=`{0}`", tle.TypeName);
}
else // TODO: more exception types
{
}
if (e.InnerException != null)
{
sb.AppendLine();
Indent(sb, d); sb.Append("Inner ");
BuildExceptionReport(e.InnerException, sb, d + 1);
}
sb.AppendLine();
Indent(sb, d); sb.Append(e.StackTrace);
return sb;
}
示例3: FormatRichTextPersistedDataForEditor
/// <summary>
/// This formats the persisted string to something useful for the rte so that the macro renders properly since we
/// persist all macro formats like {?UMBRACO_MACRO macroAlias=\"myMacro\" /}
/// </summary>
/// <param name="persistedContent"></param>
/// <param name="htmlAttributes">The html attributes to be added to the div</param>
/// <returns></returns>
/// <remarks>
/// This converts the persisted macro format to this:
///
/// {div class='umb-macro-holder'}
/// <!-- <?UMBRACO_MACRO macroAlias=\"myMacro\" /> -->
/// {ins}Macro alias: {strong}My Macro{/strong}{/ins}
/// {/div}
///
/// </remarks>
internal static string FormatRichTextPersistedDataForEditor(string persistedContent, IDictionary<string ,string> htmlAttributes)
{
return MacroPersistedFormat.Replace(persistedContent, match =>
{
if (match.Groups.Count >= 3)
{
//<div class="umb-macro-holder myMacro mceNonEditable">
var alias = match.Groups[2].Value;
var sb = new StringBuilder("<div class=\"umb-macro-holder ");
sb.Append(alias);
sb.Append(" mceNonEditable\"");
foreach (var htmlAttribute in htmlAttributes)
{
sb.Append(" ");
sb.Append(htmlAttribute.Key);
sb.Append("=\"");
sb.Append(htmlAttribute.Value);
sb.Append("\"");
}
sb.AppendLine(">");
sb.Append("<!-- ");
sb.Append(match.Groups[1].Value.Trim());
sb.Append(" />");
sb.AppendLine(" -->");
sb.Append("<ins>");
sb.Append("Macro alias: ");
sb.Append("<strong>");
sb.Append(alias);
sb.Append("</strong></ins></div>");
return sb.ToString();
}
//replace with nothing if we couldn't find the syntax for whatever reason
return "";
});
}
示例4: CommonNames
public String CommonNames(Int32 cutOff)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("Total number: " + NumberOfEntities.ToString());
List<KeyValuePair<String, Int32>> sorted = new List<KeyValuePair<String, Int32>>();
foreach ( var keyValuePair in _namesCount )
{
String name = keyValuePair.Key;
sorted.Add(keyValuePair);
}
sorted.Sort(delegate(KeyValuePair<String, Int32> x, KeyValuePair<String, Int32> y)
{
return y.Value.CompareTo(x.Value);
});
Int32 count = 0;
foreach ( var keyValuePair in sorted )
{
builder.AppendLine(keyValuePair.Key + " (" + keyValuePair.Value.ToString() + ") ");
count++;
if ( count > cutOff )
{
break;
}
}
String result = builder.ToString();
return result;
}
示例5: ToString
public override string ToString()
{
StringBuilder sb = new StringBuilder();
int tabLength = 3;
int namePad = Components.Max(c => c.Name.Length) + 2;
int detailsPad = Components.Where(c => c.Details != null).Max(c => c.Details.Length) + 2;
sb.AppendLine($"PC name: {Name}");
sb.AppendLine("Components:");
foreach (var c in Components)
{
sb.Append("".PadRight(tabLength));
sb.Append("Name: " + c.Name.PadRight(namePad));
if (c.Details != null)
{
sb.Append("Details: " + c.Details.PadRight(detailsPad));
}
sb.AppendLine("Price: " + $"{c.Price:C}");
}
sb.Append($"Total price: {Price:C}");
return sb.ToString();
}
示例6: GetModel
public DataTable GetModel(string DBConnection, IList<String> PdLine, DateTime From, DateTime To)
{
DataTable Result = null;
string selectSQL = "";
string groupbySQL = "";
groupbySQL += "GROUP by b.Descr";
string orderbySQL = "ORDER BY b.Descr";
StringBuilder sb = new StringBuilder();
//sb.AppendLine("WITH [TEMP] AS (");
sb.AppendLine(" select distinct b.Descr as Family from PCBLog a inner join Part b on a.PCBModel=b.PartNo ");
//sb.AppendLine("INNER JOIN PCB b ON a.PCBNo = b.PCBNo AND e.PartNo = b.PCBModelID ");
sb.AppendLine("WHERE a.Cdt Between @StartTime AND @EndTime and b.BomNodeType='MB' ");
if (PdLine.Count > 0)
{
sb.AppendFormat("AND a.Line in ('{0}') ", string.Join("','", PdLine.ToArray()));
}
sb.AppendFormat("{0} ", groupbySQL);
sb.AppendFormat("{0} ", orderbySQL);
Result = SQLHelper.ExecuteDataFill(DBConnection, System.Data.CommandType.Text,
sb.ToString(), new SqlParameter("@StartTime", From), new SqlParameter("@EndTime", To));
return Result;
}
示例7: GetPdLine
public DataTable GetPdLine(string Connection, string Starg)
{
string methodName = MethodBase.GetCurrentMethod().Name;
BaseLog.LoggingBegin(logger, methodName);
try
{
string SQLText = "";
StringBuilder sb = new StringBuilder();
sb.AppendLine("select substring(Line,1,1) as PdLine ");
sb.AppendLine("from Line where [email protected] ");
sb.AppendLine("group by substring(Line,1,1) ");
sb.AppendLine("order by PdLine ");
SQLText = sb.ToString();
return SQLHelper.ExecuteDataFill(Connection,
System.Data.CommandType.Text,
SQLText,
new SqlParameter("@Stage", Starg));
}
catch (Exception e)
{
BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
throw;
}
finally
{
BaseLog.LoggingEnd(logger, methodName);
}
}
示例8: ToText
public override string ToText(Subtitle subtitle, string title)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("#\tAppearance\tCaption\t");
sb.AppendLine();
int count = 1;
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
string text = HtmlUtil.RemoveHtmlTags(p.Text);
sb.AppendLine(string.Format("{0}\t{1}\t{2}\t", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.StartTime), text));
sb.AppendLine("\t\t\t\t");
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
if (next == null || Math.Abs(p.EndTime.TotalMilliseconds - next.StartTime.TotalMilliseconds) > 50)
{
count++;
sb.AppendLine(string.Format("{0}\t{1}", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.EndTime)));
}
count++;
}
RichTextBox rtBox = new RichTextBox();
rtBox.Text = sb.ToString();
string rtf = rtBox.Rtf;
rtBox.Dispose();
return rtf;
}
示例9: Page_Load
protected void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "text/plain";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + ListType + "List.txt");
StringBuilder body = new StringBuilder();
if (ListType == "White")
{
foreach (WhiteListItem wli in WhiteListItem.List(""))
{
body.AppendLine(wli.From);
}
}
if (ListType == "Black")
{
foreach (BlackListItem bli in BlackListItem.List(""))
{
body.AppendLine(bli.From);
}
}
HttpContext.Current.Response.Write(body);
HttpContext.Current.Response.End();
}
示例10: ToText
public override string ToText(Subtitle subtitle, string title)
{
const string timeCodeFormatNoHours = "{0:00}:{1:00}.{2:000}"; // h:mm:ss.cc
const string timeCodeFormatHours = "{0}:{1:00}:{2:00}.{3:000}"; // h:mm:ss.cc
const string paragraphWriteFormat = "{0} --> {1}{4}{2}{3}{4}";
var sb = new StringBuilder();
sb.AppendLine("WEBVTT FILE");
sb.AppendLine();
int count = 1;
foreach (Paragraph p in subtitle.Paragraphs)
{
string start = string.Format(timeCodeFormatNoHours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds);
string end = string.Format(timeCodeFormatNoHours, p.EndTime.Minutes, p.EndTime.Seconds, p.EndTime.Milliseconds);
if (p.StartTime.Hours > 0 || p.EndTime.Hours > 0)
{
start = string.Format(timeCodeFormatHours, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds);
end = string.Format(timeCodeFormatHours, p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, p.EndTime.Milliseconds);
}
string style = string.Empty;
if (!string.IsNullOrEmpty(p.Extra) && subtitle.Header == "WEBVTT FILE")
style = p.Extra;
sb.AppendLine(count.ToString());
sb.AppendLine(string.Format(paragraphWriteFormat, start, end, FormatText(p), style, Environment.NewLine));
count++;
}
return sb.ToString().Trim();
}
示例11: ToString
public override string ToString()
{
StringBuilder result = new StringBuilder();
result.AppendLine("Teacher name:" + base.Name);
result.AppendLine("Teacher disciplines:\n" + (string.Join("\n\n", Disciplines)));
return result.ToString();
}
示例12: Add
public ActionResult Add(string website, string title, string desc, string keywords, int parentId = 0, string layout = "", string tmpl = "blank", string locale = "")
{
var web = App.Get().Webs[string.IsNullOrEmpty(website) ? "home" : website];
if (web == null)
throw new HttpException("The " + website + " not found");
try
{
var page = App.Get().Pages.InstantiateIn(tmpl, web.Model, title, desc, keywords, parentId, string.IsNullOrEmpty(locale) ? web.DefaultLocale : locale);
if (!string.IsNullOrEmpty(layout))
{
page.ViewData = "";
page.ViewName = "~/views/dynamicui/layouts/layout_" + layout + ".cshtml";
page.Save();
}
web.ClearCache();
return Content(page.ToJsonString(), "application/json", System.Text.Encoding.UTF8);
}
catch (Exception e)
{
var sb = new StringBuilder();
sb.AppendLine(e.Message);
var etp = e.InnerException;
while (etp != null)
{
sb.AppendLine(etp.Message);
etp = etp.InnerException;
}
throw new HttpException(sb.ToString());
//return new HttpStatusCodeResult(500, sb.ToString());
}
}
示例13: Parse
public void Parse(Cursor cursor)
{
if (String.IsNullOrEmpty(cursor.Name))
return;
String enumName = cursor.Name.Substring(2).Replace("_", "");
if (enumName == "ChildVisitResult")
enumName = "CursorVisitResult";
if (enumName == "CallingConv")
enumName = "CallingConvention";
String filename = Path.Combine(_di.FullName, enumName + ".h");
var contents = new StringBuilder();
contents.AppendLine(Template.Template.Header);
if (enumName.EndsWith("Flags"))
contents.AppendLine(" [System::Flags]");
contents.Append(" public enum class ");
contents.Append(enumName);
contents.AppendLine(" {");
// add values
_sb = contents;
cursor.VisitChildren(EnumVisitor);
contents.AppendLine(" };");
contents.AppendLine(Template.Template.Footer);
File.WriteAllText(filename, contents.ToString());
}
示例14: btnBrowser_Click
private void btnBrowser_Click(object sender, EventArgs e)
{
string s = txtCharOrString.Text;
StringBuilder sbResult = new StringBuilder();
int i16;
byte[] array = System.Text.Encoding.Default.GetBytes(s);
for (int i = 0; i < array.Length; i++)
{
if (array[i] >= 128 && array[i] <= 247)
{
sbResult.Append(System.Text.Encoding.Default.GetString(array, i, 2));
i16 = int.Parse(array[i].ToString("X2") + array[i + 1].ToString("X2"), System.Globalization.NumberStyles.HexNumber);
sbResult.AppendLine(string.Format(" 高字节:{0},低字节:{1},机内码:{2}", array[i], array[i + 1], i16));
i++;
}
else
{
sbResult.Append(System.Text.Encoding.Default.GetString(array, i, 1));
sbResult.AppendLine(string.Format(" ASCII:{0}" , array[i]));
}
}
txtResult.Text = sbResult.ToString();
}
示例15: FormatParameters
/// <summary>
/// Formats the given parameters to call a function.
/// </summary>
/// <param name="parameters">An array of parameters.</param>
/// <returns>The mnemonics to pass the parameters.</returns>
public string FormatParameters(IntPtr[] parameters)
{
// Declare a var to store the mnemonics
var ret = new StringBuilder();
var paramList = new List<IntPtr>(parameters);
// Store the first parameter in the ECX register
if (paramList.Count > 0)
{
ret.AppendLine("mov ecx, " + paramList[0]);
paramList.RemoveAt(0);
}
// Store the second parameter in the EDX register
if (paramList.Count > 0)
{
ret.AppendLine("mov edx, " + paramList[0]);
paramList.RemoveAt(0);
}
// For each parameters (in reverse order)
paramList.Reverse();
foreach (var parameter in paramList)
{
ret.AppendLine("push " + parameter);
}
// Return the mnemonics
return ret.ToString();
}