本文整理汇总了C#中System.Text.StringBuilder类的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder类的具体用法?C# StringBuilder怎么用?C# StringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringBuilder类属于System.Text命名空间,在下文中一共展示了StringBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConcatString
/// <summary>
/// Concatenates any given IEnumerable to joined string, null-ignorance
/// </summary>
/// <param name="objects"> any set of objects of any type </param>
/// <param name="delimiter"> delimiter between strings </param>
/// <param name="empties"> true - empties included in result </param>
/// <param name="nullstring"> null replacer (null by default) </param>
/// <param name="useTrailDelimiters"> if true - trail delimiters will be generated </param>
/// <returns> </returns>
public string ConcatString(IEnumerable objects, string delimiter, bool empties = true,
string nullstring = null,
bool useTrailDelimiters = false) {
if (null == objects) {
return string.Empty;
}
if (null == delimiter) {
delimiter = string.Empty;
}
var result = new StringBuilder();
if (useTrailDelimiters) {
result.Append(delimiter);
}
var first = true;
foreach (var obj in objects) {
var val = obj.ToStr();
if (val.IsEmpty() && !empties) {
continue;
}
if (null == obj && null != nullstring) {
val = nullstring;
}
if (!first) {
result.Append(delimiter);
}
if (first) {
first = false;
}
result.Append(val);
}
if (useTrailDelimiters) {
result.Append(delimiter);
}
return result.ToString();
}
示例2: GetMd5Sum
// Create an md5 sum string of this string
public static string GetMd5Sum(this string str)
{
// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);
// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
var sb = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
sb.Append(result[i].ToString("X2"));
}
// And return it
return sb.ToString();
}
示例3: GetDetails
public string GetDetails()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("This demo shows how to setup complex collision scenerios.");
sb.AppendLine("In this demo:");
sb.AppendLine(" - Circles and rectangles are set to only collide with themselves.");
sb.AppendLine(" - Stars are set to collide with gears.");
sb.AppendLine(" - Gears are set to collide with stars.");
sb.AppendLine(" - The agent is set to collide with everything but stars");
sb.AppendLine(string.Empty);
sb.AppendLine("GamePad:");
sb.AppendLine(" - Rotate agent: left and right triggers");
sb.AppendLine(" - Move agent: right thumbstick");
sb.AppendLine(" - Move cursor: left thumbstick");
sb.AppendLine(" - Grab object (beneath cursor): A button");
sb.AppendLine(" - Drag grabbed object: left thumbstick");
sb.AppendLine(" - Exit to menu: Back button");
sb.AppendLine(string.Empty);
sb.AppendLine("Keyboard:");
sb.AppendLine(" - Rotate agent: left and right arrows");
sb.AppendLine(" - Move agent: A,S,D,W");
sb.AppendLine(" - Exit to menu: Escape");
sb.AppendLine(string.Empty);
sb.AppendLine("Mouse / Touchscreen");
sb.AppendLine(" - Grab object (beneath cursor): Left click");
sb.AppendLine(" - Drag grabbed object: move mouse / finger");
return sb.ToString();
}
示例4: Replace
public string Replace (string str)
{
if (string.IsNullOrEmpty (str)) {
return str;
}
System.Text.StringBuilder formatted = new System.Text.StringBuilder ();
int lastMatch = 0;
string variable;
string replacement;
foreach (System.Text.RegularExpressions.Match m in re.Matches(str)) {
formatted.Append (str.Substring (lastMatch, m.Index - lastMatch));
variable = m.Groups [1].Value;
if (vars.TryGetValue (variable, out replacement))
formatted.Append (this.Replace (replacement));
else
throw new ObfuscarException("Unable to replace variable: " + variable);
lastMatch = m.Index + m.Length;
}
formatted.Append (str.Substring (lastMatch));
return formatted.ToString ();
}
示例5: AddModulePermission
/// <summary>
/// 分配角色模块菜单权限
/// </summary>
/// <param name="KeyValue">主键值</param>
/// <param name="RoleId">角色主键</param>
/// <param name="CreateUserId">操作用户主键</param>
/// <param name="CreateUserName">操作用户</param>
/// <returns></returns>
public bool AddModulePermission(string[] KeyValue, string RoleId, string CreateUserId, string CreateUserName)
{
//return dal.AddModulePermission(KeyValue, RoleId, CreateUserId, CreateUserName) >= 0 ? true : false;
StringBuilder[] sqls = new StringBuilder[KeyValue.Length + 1];
object[] objs = new object[KeyValue.Length + 1];
sqls[0] = SqlParamHelper.DeleteSql("AMS_RoleMenu", "RoleId");
objs[0] = new SqlParam[] { new SqlParam("@RoleId", RoleId) };
int index = 1;
foreach (string item in KeyValue)
{
if (item.Length > 0)
{
AMS_RoleMenu entity = new AMS_RoleMenu();
entity.RoleMenuId = CommonHelper.GetGuid;
entity.RoleId = RoleId;
entity.MenuId = item;
entity.CreateUserId = CreateUserId;
entity.CreateUserName = CreateUserName;
sqls[index] = SqlParamHelper.InsertSql(entity);
objs[index] = SqlParamHelper.GetParameter(entity);
index++;
}
}
int IsOK = DbHelper.BatchExecuteBySql(sqls, objs);
return IsOK >= 0 ? true : false;
}
示例6: GenerateCode
void GenerateCode(string name)
{
System.Text.StringBuilder builder = new System.Text.StringBuilder ();
builder.AppendLine ("using UnityEngine;");
builder.AppendLine ("using System.Collections;");
builder.AppendLine ("");
builder.AppendLine ("public class " + name + " : State {");
builder.AppendLine ("");
builder.AppendLine ("public override void StateStart ()");
builder.AppendLine ("{");
builder.AppendLine (" Debug.Log (this.ToString() + \" Start!\");");
builder.AppendLine ("");
builder.AppendLine ("}");
builder.AppendLine ("");
builder.AppendLine ("public override void StateUpdate ()");
builder.AppendLine ("{");
builder.AppendLine ("");
builder.AppendLine (" if(Input.GetKeyDown(KeyCode.A)){");
builder.AppendLine (" this.EndState();");
builder.AppendLine (" }");
builder.AppendLine (" ");
builder.AppendLine ("}");
builder.AppendLine ("");
builder.AppendLine ("public override void StateDestroy ()");
builder.AppendLine ("{");
builder.AppendLine (" Debug.Log (this.ToString() + \" Destroy!\");");
builder.AppendLine ("}");
builder.AppendLine ("");
builder.AppendLine ("}");
System.IO.File.WriteAllText (ScriptsPath + "/" + name + ".cs", builder.ToString (), System.Text.Encoding.UTF8);
AssetDatabase.Refresh (ImportAssetOptions.ImportRecursive);
}
示例7: AsEsql
internal override StringBuilder AsEsql(StringBuilder builder, bool isTopLevel, int indentLevel)
{
// The SELECT/DISTINCT part.
StringUtil.IndentNewLine(builder, indentLevel);
builder.Append("SELECT ");
if (m_selectDistinct == CellQuery.SelectDistinct.Yes)
{
builder.Append("DISTINCT ");
}
GenerateProjectionEsql(builder, m_nodeTableAlias, true, indentLevel, isTopLevel);
// Get the FROM part.
builder.Append("FROM ");
CqlWriter.AppendEscapedQualifiedName(builder, m_extent.EntityContainer.Name, m_extent.Name);
builder.Append(" AS ").Append(m_nodeTableAlias);
// Get the WHERE part only when the expression is not simply TRUE.
if (!BoolExpression.EqualityComparer.Equals(WhereClause, BoolExpression.True))
{
StringUtil.IndentNewLine(builder, indentLevel);
builder.Append("WHERE ");
WhereClause.AsEsql(builder, m_nodeTableAlias);
}
return builder;
}
示例8: CloneCmd
public static string CloneCmd(string fromSvn, string toPath, string username,
string authorsFile, int fromRevision,
string trunk, string tags, string branches)
{
toPath = GitCommandHelpers.FixPath(toPath);
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0} clone \"{1}\" \"{2}\"", SvnPrefix, fromSvn, toPath);
if (!string.IsNullOrEmpty(username))
{
sb.AppendFormat(" --username=\"{0}\"", username);
}
if (!string.IsNullOrEmpty(authorsFile))
{
sb.AppendFormat(" --authors-file=\"{0}\"", authorsFile);
}
if (fromRevision != 0)
{
sb.AppendFormat(" -r \"{0}\"", fromRevision);
}
if (!string.IsNullOrEmpty(trunk))
{
sb.AppendFormat(" --trunk=\"{0}\"", trunk);
}
if (!string.IsNullOrEmpty(tags))
{
sb.AppendFormat(" --tags=\"{0}\"", tags);
}
if (!string.IsNullOrEmpty(branches))
{
sb.AppendFormat(" --branches=\"{0}\"", branches);
}
return sb.ToString();
}
示例9: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
ReciboBE reciboBE;
//if (Session["ReciboBE"] != null)
//{
reciboBE = Session["ReciboBE"] as ReciboBE;
//}
CarregaProfissional(Convert.ToInt32(reciboBE.RefProfissionalBE.id));
lblReciboNumero.Text = Convert.ToString(reciboBE.id);
lblValorTotalCabecalho.Text = String.Format("{0:C2}", reciboBE.ValorTotal);
lblValorTotal.Text = String.Format("{0:C2}", reciboBE.ValorTotal);
lblSessoesQtd.Text = Convert.ToString(reciboBE.RefReciboAgendamentoSessoesBE.Count.ToString("00"));
lblPacienteNome.Text = Convert.ToString(reciboBE.PacienteNome);
//Pego a possicao zero da lista de sessooes
lblValorSessao.Text = String.Format("{0:C2}", reciboBE.RefReciboAgendamentoSessoesBE[0].Valor);
StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < reciboBE.RefReciboAgendamentoSessoesBE.Count; i++)
{
if (i > 0)
sb.Append(", ");
sb.Append(reciboBE.RefReciboAgendamentoSessoesBE[i].Data.ToString("dd/MM/yyyy"));
}
lblDatas.Text = Convert.ToString(sb);
DataExtenso();
}
示例10: GetHelp
public static IEnumerable<string> GetHelp(ScriptSession session, string command)
{
Collection<PSParseError> errors;
var tokens = PSParser.Tokenize(command, out errors);
var lastPsToken = tokens.LastOrDefault(t => t.Type == PSTokenType.Command);
if (lastPsToken != null)
{
session.Output.Clear();
var lastToken = lastPsToken.Content;
session.SetVariable("helpFor", lastToken);
var platformmodule = ModuleManager.GetModule("Platform");
var scriptItem = Database.GetDatabase(platformmodule.Database)
.GetItem(platformmodule.Path + "/Internal/Context Help/Command Help");
if (scriptItem == null)
{
scriptItem = Factory.GetDatabase(ApplicationSettings.ScriptLibraryDb)
.GetItem(ApplicationSettings.ScriptLibraryPath + "Internal/Context Help/Command Help");
}
session.ExecuteScriptPart(scriptItem[ScriptItemFieldNames.Script], true, true);
var sb = new StringBuilder("<div id=\"HelpClose\">X</div>");
if (session.Output.Count == 0 || session.Output[0].LineType == OutputLineType.Error)
{
return new[]
{
"<div class='ps-help-command-name'> </div><div class='ps-help-header' align='center'>No Command in line or help information found</div><div class='ps-help-parameter' align='center'>Cannot provide help in this context.</div>"
};
}
session.Output.ForEach(l => sb.Append(l.Text));
session.Output.Clear();
var result = new[] {sb.ToString()};
return result;
}
return new[] {"No Command in line found - cannot provide help in this context."};
}
示例11: ToString
public override string ToString()
{
if (PageCount == 1)
return "";
var sb = new StringBuilder(512);
sb.Append(@"<div class=""");
sb.Append(CssClass);
sb.Append(@""">");
foreach (int pageSize in PageSizes)
{
sb.Append(@"<a href=""");
sb.Append(HRef.Replace("pagesize=-1", "pagesize=" + pageSize));
sb.Append(@""" title=""");
sb.Append("show ");
sb.Append(pageSize);
sb.Append(@" items per page""");
if (pageSize == CurrentPageSize)
sb.Append(@" class=""current page-numbers""");
else
sb.Append(@" class=""page-numbers""");
sb.Append(">");
sb.Append(pageSize);
sb.AppendLine("</a>");
}
sb.AppendLine(@"<span class=""page-numbers desc"">per page</span>");
sb.Append("</div>");
return sb.ToString();
}
示例12: FormatAlterTable
protected virtual string FormatAlterTable(string sql)
{
StringBuilder result = new StringBuilder(60).Append(Indent1);
IEnumerator<string> tokens = (new StringTokenizer(sql, " (,)'[]\"", true)).GetEnumerator();
bool quoted = false;
while (tokens.MoveNext())
{
string token = tokens.Current;
if (IsQuote(token))
{
quoted = !quoted;
}
else if (!quoted)
{
if (IsBreak(token))
{
result.Append(Indent3);
}
}
result.Append(token);
}
return result.ToString();
}
示例13: FormatCommentOn
protected virtual string FormatCommentOn(string sql)
{
StringBuilder result = new StringBuilder(60).Append(Indent1);
IEnumerator<string> tokens = (new StringTokenizer(sql, " '[]\"", true)).GetEnumerator();
bool quoted = false;
while (tokens.MoveNext())
{
string token = tokens.Current;
result.Append(token);
if (IsQuote(token))
{
quoted = !quoted;
}
else if (!quoted)
{
if ("is".Equals(token))
{
result.Append(Indent2);
}
}
}
return result.ToString();
}
示例14: GetRouteDescriptorKey
public string GetRouteDescriptorKey(HttpContextBase httpContext, RouteBase routeBase) {
var route = routeBase as Route;
var dataTokens = new RouteValueDictionary();
if (route != null) {
dataTokens = route.DataTokens;
}
else {
var routeData = routeBase.GetRouteData(httpContext);
if (routeData != null) {
dataTokens = routeData.DataTokens;
}
}
var keyBuilder = new StringBuilder();
if (route != null) {
keyBuilder.AppendFormat("url={0};", route.Url);
}
// the data tokens are used in case the same url is used by several features, like *{path} (Rewrite Rules and Home Page Provider)
if (dataTokens != null) {
foreach (var key in dataTokens.Keys) {
keyBuilder.AppendFormat("{0}={1};", key, dataTokens[key]);
}
}
return keyBuilder.ToString().ToLowerInvariant();
}
示例15: AsNegatedUserString
internal override StringBuilder AsNegatedUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
{
builder.Append("NOT(");
builder = AsUserString(builder, blockAlias, skipIsNotNull);
builder.Append(")");
return builder;
}