当前位置: 首页>>代码示例>>C#>>正文


C# Text.StringBuilder类代码示例

本文整理汇总了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();
		}
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:44,代码来源:StringHelper.cs

示例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();
        }
开发者ID:jcoxhead,项目名称:SilverlightExamples,代码行数:26,代码来源:Md5Sum.cs

示例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();
 }
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:28,代码来源:SimpleDemo5.cs

示例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 ();
		}
开发者ID:jerryhuffman,项目名称:obfuscar,代码行数:29,代码来源:Variables.cs

示例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;
 }
开发者ID:xiaolin8,项目名称:AMS,代码行数:34,代码来源:AMS_RoleMenuBLL.cs

示例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);
    }
开发者ID:MasatomoSegawa,项目名称:SuiteMassShipura,代码行数:33,代码来源:mySceneEdit.cs

示例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;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:26,代码来源:ExtentCqlBlock.cs

示例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();
 }
开发者ID:PaulGardens,项目名称:gitextensions,代码行数:33,代码来源:GitSvnCommandHelpers.cs

示例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();
    }
开发者ID:danygolden,项目名称:gianfratti,代码行数:31,代码来源:ReciboSalvar.aspx.cs

示例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'>&nbsp;</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."};
 }
开发者ID:sobek85,项目名称:Console,代码行数:34,代码来源:CommandHelp.cs

示例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();
        }
开发者ID:jango2015,项目名称:StackExchange.DataExplorer,代码行数:32,代码来源:PageSizer.cs

示例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();
		}
开发者ID:jlevitt,项目名称:nhibernate-core,代码行数:25,代码来源:DdlFormatter.cs

示例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();
		}
开发者ID:jlevitt,项目名称:nhibernate-core,代码行数:25,代码来源:DdlFormatter.cs

示例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();
        }
开发者ID:mikmakcar,项目名称:orchard_fork_learning,代码行数:30,代码来源:CacheService.cs

示例15: AsNegatedUserString

 internal override StringBuilder AsNegatedUserString(StringBuilder builder, string blockAlias, bool skipIsNotNull)
 {
     builder.Append("NOT(");
     builder = AsUserString(builder, blockAlias, skipIsNotNull);
     builder.Append(")");
     return builder;
 }
开发者ID:uQr,项目名称:referencesource,代码行数:7,代码来源:CellIdBoolean.cs


注:本文中的System.Text.StringBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。