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


C# StringBuilder.AppendFormat方法代码示例

本文整理汇总了C#中System.Text.StringBuilder.AppendFormat方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendFormat方法的具体用法?C# StringBuilder.AppendFormat怎么用?C# StringBuilder.AppendFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.StringBuilder的用法示例。


在下文中一共展示了StringBuilder.AppendFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Inserir

        /// <exception cref="MyException"></exception>
        public void Inserir(ICliente cliente, ILog log)
        {
            var sql = new StringBuilder();
            var tblLog = new TblClientesLog();

            sql.AppendFormat(" INSERT INTO {0} ({1},{2},{3}", tblLog.NomeTabela, tblLog.Clientes_Id, tblLog.Clientes_Nome, tblLog.Clientes_Status_Id);
            sql.AppendFormat(",{0},{1},{2})", tblLog.Usuarios_Id, tblLog.Operacao_Id, tblLog.DataHora);
            sql.Append(" VALUES (@id,@nome,@status_id");
            sql.Append(",@usuarios_id,@operacao_id,@datahora);");

            using (var dal = new DalHelperSqlServer())
            {
                try
                {
                    dal.CriarParametroDeEntrada("id", SqlDbType.Int, cliente.Id);
                    dal.CriarParametroDeEntrada("nome", SqlDbType.Char, cliente.Nome);
                    dal.CriarParametroDeEntrada("status_id", SqlDbType.SmallInt, cliente.Status.GetHashCode());
                    dal.CriarParametroDeEntrada("usuarios_id", SqlDbType.Int, log.Usuario.Id);
                    dal.CriarParametroDeEntrada("operacao_id", SqlDbType.SmallInt, log.Operacao.GetHashCode());
                    dal.CriarParametroDeEntrada("datahora", SqlDbType.DateTime, log.DataHora);

                    dal.ExecuteNonQuery(sql.ToString());
                }
                catch (SqlException) { throw new MyException("Operação não realizada, por favor, tente novamente!"); }
            }
        }
开发者ID:phcbarros,项目名称:Estudos,代码行数:27,代码来源:DaoClienteLog.cs

示例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;
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:30,代码来源:Program.cs

示例3: GetFilterText

        public string GetFilterText()
        {
            StringBuilder sb = new StringBuilder("<filter>");

            if (Tests.Count > 0)
            {
                sb.Append("<tests>");
                foreach (string test in Tests)
                    sb.AppendFormat("<test>{0}</test>", test);
                sb.Append("</tests>");
            }

            if (Include.Count > 0)
            {
                sb.Append("<include>");
                foreach (string category in Include)
                    sb.AppendFormat("<category>{0}</category>", category);
                sb.Append("</include>");
            }

            if (Exclude.Count > 0)
            {
                sb.Append("<exclude>");
                foreach (string category in Exclude)
                    sb.AppendFormat("<category>{0}</category>", category);
                sb.Append("</exclude>");
            }

            sb.Append("</filter>");

            return sb.ToString();
        }
开发者ID:haf,项目名称:nunit-framework,代码行数:32,代码来源:TestFilterBuilder.cs

示例4: PostReport

        /// <summary>
        /// Report a post
        /// </summary>
        /// <param name="report"></param>
        public void PostReport(Report report)
        {
            var sb = new StringBuilder();
            var email = new Email();

            sb.AppendFormat("<p>{2}: <a href=\"{0}\">{1}</a></p>", string.Concat(_settingsService.GetSettings().ForumUrl, report.Reporter.NiceUrl), 
                report.Reporter.UserName,
                _localizationService.GetResourceString("Report.Reporter"));

            sb.AppendFormat("<p>{2}: <a href=\"{0}\">{1}</a></p>", string.Concat(_settingsService.GetSettings().ForumUrl, 
                report.ReportedPost.Topic.NiceUrl), report.ReportedPost.Topic.Name,
                _localizationService.GetResourceString("Report.PostReported"));

            sb.AppendFormat("<p>{0}:</p>", _localizationService.GetResourceString("Report.Reason"));
            sb.AppendFormat("<p>{0}</p>", report.Reason);

            email.EmailFrom = _settingsService.GetSettings().NotificationReplyEmail;
            email.EmailTo = _settingsService.GetSettings().AdminEmailAddress;
            email.Subject = _localizationService.GetResourceString("Report.PostReport");
            email.NameTo = _localizationService.GetResourceString("Report.Admin");

            email.Body = _emailService.EmailTemplate(email.NameTo, sb.ToString());

            _emailService.SendMail(email);
        }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:29,代码来源:ReportService.cs

示例5: GetImageTag

        public string GetImageTag(int? imageId, int? maxWidth = null, int? maxHeight = null )
        {
            var photoUrl = new StringBuilder();

            photoUrl.Append( System.Web.VirtualPathUtility.ToAbsolute( "~/" ) );

            string styleString = string.Empty;

            if ( imageId.HasValue )
            {
                photoUrl.AppendFormat( "GetImage.ashx?id={0}", imageId );

                if ( maxWidth.HasValue )
                {
                    photoUrl.AppendFormat( "&maxwidth={0}", maxWidth.Value );
                }
                if ( maxHeight.HasValue )
                {
                    photoUrl.AppendFormat( "&maxheight={0}", maxHeight.Value );
                }
            }
            else
            {
                photoUrl.Append( "Assets/Images/no-picture.svg?" );

                if ( maxWidth.HasValue || maxHeight.HasValue )
                {
                    styleString = string.Format( " style='{0}{1}'",
                        maxWidth.HasValue ? "max-width:" + maxWidth.Value.ToString() + "px; " : "",
                        maxHeight.HasValue ? "max-height:" + maxHeight.Value.ToString() + "px;" : "" );
                }
            }

            return string.Format( "<img src='{0}'{1}/>", photoUrl.ToString(), styleString );
        }
开发者ID:Higherbound,项目名称:Higherbound-2016-website-upgrades,代码行数:35,代码来源:LocationDetail.ascx.cs

示例6: makeWhere

		private string makeWhere(Uri url)
		{
			Stack<string> hostStack = new Stack<string>(url.Host.Split('.'));
			StringBuilder hostBuilder = new StringBuilder('.' + hostStack.Pop());
			string[] pathes = url.Segments;

			StringBuilder sb = new StringBuilder();
			sb.Append("WHERE (");

			bool needOr = false;
			while (hostStack.Count != 0) {
				if (needOr) {
					sb.Append(" OR");
				}

				if (hostStack.Count != 1) {
					hostBuilder.Insert(0, '.' + hostStack.Pop());
					sb.AppendFormat(" host = \"{0}\"", hostBuilder.ToString());
				} else {
					hostBuilder.Insert(0, '%' + hostStack.Pop());
					sb.AppendFormat(" host LIKE \"{0}\"", hostBuilder.ToString());
				}

				needOr = true;
			}

			sb.Append(')');
			return sb.ToString();
		}
开发者ID:nico-lab,项目名称:niconama-ocv,代码行数:29,代码来源:Firefox3CookieGetter.cs

示例7: Compute

 public override void Compute()
 {
     TLKeyValuePairsList precision = (TLKeyValuePairsList)Workspace.Load("PrecisionData");
     TLKeyValuePairsList recall = (TLKeyValuePairsList)Workspace.Load("RecallData");
     TLKeyValuePairsList avgprecision = (TLKeyValuePairsList)Workspace.Load("AvgPrecisionData");
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("{0}\n", _config.Title);
     sb.AppendLine("--------------------------------------------------");
     sb.AppendFormat("Precision Data:\nMin:\t{0}\nMax:\t{1}\nAvg:\t{2}\n",
         GetMin(precision),
         GetMax(precision),
         GetAvg(precision)
     );
     sb.AppendLine("--------------------------------------------------");
     sb.AppendFormat("Recall Data:\nMin:\t{0}\nMax:\t{1}\nAvg:\t{2}\n",
         GetMin(recall),
         GetMax(recall),
         GetAvg(recall)
     );
     sb.AppendLine("--------------------------------------------------");
     sb.AppendFormat("Avg Precision Data:\nMin:\t{0}\nMax:\t{1}\nAvg:\t{2}\n",
         GetMin(avgprecision),
         GetMax(avgprecision),
         GetAvg(avgprecision)
     );
     sb.AppendLine("--------------------------------------------------");
     /*
     SimpleResultsWindow window = new SimpleResultsWindow();
     window.PrintToScreen(sb.ToString());
     window.ShowDialog();
     */
     Logger.Info(sb.ToString());
 }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:33,代码来源:SimpleResultsGUI.cs

示例8: MenuLinks

        // 生成界面左边菜单
        public static MvcHtmlString MenuLinks(this HtmlHelper html,
          List<IMS_UP_MK> menuList)
        {
            if (menuList == null)
                return new MvcHtmlString("");

            long? lastIdx = -1;
            StringBuilder result = new StringBuilder();
            foreach (var menu in menuList)
            {
                if (menu.FMKID  == -1)
                {
                    if (lastIdx != -1 && lastIdx != menu.ID)
                    {
                        result.Append("</ul></div>");
                    }
                    lastIdx = menu.ID;
                    result.AppendFormat("<div title='{0}'>", menu.MKMC);
                    result.Append("<ul class='content' >");
                }
                else
                {
                    result.Append("<li>");
                    //result.AppendFormat("<a href='{0}' target='ibody'>{1}</a>", menu.URL, menu.ModuleName);
                    result.AppendFormat(@"<a href='###' onclick=""mainPage.onMenuClick('{0}','{1}','{2}');"">{1}</a>", menu.ID, menu.MKMC,   menu.URL);
                    result.Append("</li>");


                }
            }
            result.Append("</ul></div>");
            return MvcHtmlString.Create(result.ToString());
        }
开发者ID:mmxftp,项目名称:JSMiracle.AutoWarehouse,代码行数:34,代码来源:MenuHelpers.cs

示例9: DoSearch

        private void DoSearch()
        {
            // 既存データクリア
            listDataGridView.Rows.Clear();

            DataTable table = GetData();

            StringBuilder cond = new StringBuilder();
            if (!string.IsNullOrEmpty(nendoTextBox.Text))
            {
                if (cond.Length > 0) { cond.Append(" AND "); }
                cond.AppendFormat("IraiNendo = '{0}'", nendoTextBox.Text);
            }
            if (!string.IsNullOrEmpty(noFromTextBox.Text))
            {
                if (cond.Length > 0) { cond.Append(" AND "); }
                cond.AppendFormat("IraiRenban >= '{0}'", noFromTextBox.Text);
            }
            if (!string.IsNullOrEmpty(noToTextBox.Text))
            {
                if (cond.Length > 0) { cond.Append(" AND "); }
                cond.AppendFormat("IraiRenban <= '{0}'", noToTextBox.Text);
            }

            // TODO 製品版では、クエリ内でフィルタを行う
            foreach (DataRow row in table.Select(cond.ToString()))
            {
                SetData(row);
            }
        }
开发者ID:25cm,项目名称:HelloWorld,代码行数:30,代码来源:SuishitsuKensaDaicho.cs

示例10: ToString

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("State {0}", num);
            builder.AppendLine();
            builder.AppendLine();

            foreach (ProductionItem item in kernelItems)
            {
                builder.AppendFormat("    {0}", item);
                builder.AppendLine();
            }

            builder.AppendLine();

            foreach (KeyValuePair<Terminal, ParserAction> a in parseTable)
            {
                builder.AppendFormat("    {0,-14} {1}", a.Key, a.Value);
                builder.AppendLine();
            }

            builder.AppendLine();

            foreach (KeyValuePair<NonTerminal, Transition> n in nonTerminalTransitions)
            {
                builder.AppendFormat("    {0,-14} go to state {1}", n.Key, Goto[n.Key].num);
                builder.AppendLine();
            }

            builder.AppendLine();

            return builder.ToString();
        }
开发者ID:KommuSoft,项目名称:Gardens-Point-Parser-Generator,代码行数:34,代码来源:State.cs

示例11: Format

        public static void Format(FtpCommandContext context, FileSystemInfo fileInfo, StringBuilder output)
        {
            var isFile = fileInfo is FileInfo;

            //Size
            output.AppendFormat("size={0};", isFile ? ((FileInfo)fileInfo).Length : 0);

            //Permission
            output.AppendFormat("perm={0}{1};",
                                /* Can read */ isFile ? "r" : "el",
                                /* Can write */ isFile ? "adfw" : "fpcm");
            
            //Type
            output.AppendFormat("type={0};", isFile ? "file" : "dir");

            //Create
            output.AppendFormat("create={0};", FtpDateUtils.FormatFtpDate(fileInfo.CreationTimeUtc));

            //Modify
            output.AppendFormat("modify={0};", FtpDateUtils.FormatFtpDate(fileInfo.LastWriteTimeUtc));

            //File name
            output.Append(DELIM);
            output.Append(fileInfo.Name);

            output.Append(NEWLINE);
        }
开发者ID:Flagwind,项目名称:Zongsoft.CoreLibrary,代码行数:27,代码来源:FtpMlstFileFormater.cs

示例12: Time

        /// <summary>
        /// 无参数动作执行时间 返回详细信息
        /// </summary>
        /// <example>
        /// <code>
        /// Msg.WriteEnd(ActionExtensions.Time(() => { Msg.Write(1); }, "测试", 1000));
        /// </code>
        /// </example>
        /// <param name="action">动作</param>
        /// <param name="name">测试名称</param>
        /// <param name="iteration">执行次数</param>
        /// <returns>返回执行时间毫秒(ms)</returns>
        public static string Time(this Action action, string name = "", int iteration = 1) {
            if (name.IsNullEmpty()) {
                var watch = Stopwatch.StartNew();
                long cycleCount = WinApi.GetCycleCount();
                for (int i = 0; i < iteration; i++) action();
                long cpuCycles = WinApi.GetCycleCount() - cycleCount;
                watch.Stop();
                return watch.Elapsed.ToString();
            } else {
                StringBuilder sb = new StringBuilder();

                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                int[] gcCounts = new int[GC.MaxGeneration + 1];
                for (int i = 0; i <= GC.MaxGeneration; i++) gcCounts[i] = GC.CollectionCount(i);

                var watch = Stopwatch.StartNew();
                long cycleCount = WinApi.GetCycleCount();
                for (int i = 0; i < iteration; i++) action();
                long cpuCycles = WinApi.GetCycleCount() - cycleCount;
                watch.Stop();

                sb.AppendFormat("{0} 循环{1}次测试结果:<br />", name, iteration);
                sb.AppendFormat("使用时间:{0}<br />", watch.Elapsed.ToString());
                sb.AppendFormat("CPU周期:{0}<br />", cpuCycles.ToString("N0"));

                for (int i = 0; i <= GC.MaxGeneration; i++) sb.AppendFormat("Gen  {0}:{1}<br />", i, GC.CollectionCount(i) - gcCounts[i]);
                sb.Append("<br />");
                return sb.ToString();
            }
        }
开发者ID:pczy,项目名称:Pub.Class,代码行数:42,代码来源:ActionExtensions.cs

示例13: HierarchicalCatalogView

        private string HierarchicalCatalogView(CrcReportFolder rootFolder, int level, string showFolder)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<div class=\"folderBox\">");
            string scrollTo = "";
            if (PathMatch(showFolder, rootFolder.Path))
                scrollTo = " scrollToFolder";
            sb.AppendFormat("<div class=\"folderName{1}\">{0}</div>", rootFolder.FolderName, scrollTo);
            string show = "none";
            if (level == 0 || PathContains(showFolder, rootFolder.Path))
                show = "block";

            sb.AppendFormat("<div class=\"folderChildren\" style=\"display:{0}\">", show);

            foreach (CrcReportFolder subFolderLoop in rootFolder.SubFolders)
                sb.Append(HierarchicalCatalogView(subFolderLoop, level + 1, showFolder));

            foreach (CrcReportItem itemLoop in rootFolder.Reports)
            {

                sb.Append("<div class=\"reportRow\">");
                sb.AppendFormat("<a class=\"reportLink vanillaHover\" href=\"Report.aspx?path={0}\" >{1}</a>",
                    Server.UrlEncode(itemLoop.ReportPath), itemLoop.DisplayName);
                if (!string.IsNullOrEmpty(itemLoop.ShortDescription))
                    sb.AppendFormat("<div class=\"reportInfo\">{0}</div>", itemLoop.ShortDescription);
                sb.Append("<div class=\"clear\"></div></div>");

            }

            sb.Append("</div></div>");
            return sb.ToString();
        }
开发者ID:pallu,项目名称:crisscross,代码行数:32,代码来源:HierarchicalCatalog.ascx.cs

示例14: StringBuilder

        void IGrowlSender.SendNotification(IGrowlJob growl, string headline, string text)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("https://www.notifymyandroid.com/publicapi/notify?");
            // API-Key(s)
            sb.AppendFormat("apikey={0}", string.Join(",", growl.GetApiKeys()));
            // Application name
            sb.AppendFormat("&application={0}", HttpUtility.UrlEncode(growl.ApplicationName));
            // Event (max. 1000 chars)
            sb.AppendFormat("&event={0}", HttpUtility.UrlEncode(headline.Truncate(1000, true, true)));
            // Description (max. 10000 chars)
            sb.AppendFormat("&description={0}", HttpUtility.UrlEncode(text.Truncate(10000, true, true)));
            // Priority
            sb.AppendFormat("&priority={0}", EmergencyPriority);

            WebRequest notificationRequest = WebRequest.Create(sb.ToString());
            WebResponse notificationResponse = notificationRequest.GetResponse();

            NMAResponse logicalResponse = NMAResponse.ReadResponse(notificationResponse);
            if (!logicalResponse.IsSuccess)
            {
                Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.NMAApiKeyIsInvalid, logicalResponse.Message);
            }
            if (!logicalResponse.CanSendAnotherRequest)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, Properties.Resources.NMANoRemainingRequestsLeft, logicalResponse.ResetTimer);
            }
        }
开发者ID:The-Stig,项目名称:AlarmWorkflow,代码行数:28,代码来源:NotifyMyAndroidGrowlSender.cs

示例15: FormatHtml

        public string FormatHtml(object data)
        {
            const string keywordFormat = "<span style=\"color: #0000FF\">{0}</span>";
            const string typeFormat = "<span style=\"color: #2B91AF\">{0}</span>";

            var methodInfo = (MethodInfo)data;
            var sb = new StringBuilder();
            var declaringType = methodInfo.DeclaringType;
            sb.AppendFormat("{0} {1}.{2} {{ ",
                string.Format(keywordFormat, "class"),
                declaringType.Namespace,
                string.Format(typeFormat, declaringType.Name));

            AppendAccess(methodInfo, sb, keywordFormat);

            if (methodInfo.IsVirtual)
            {
                sb.AppendFormat(keywordFormat, "virtual");
                sb.Append(" ");
            }

            AppendMethodName(methodInfo, sb);
            sb.Append(" (...)");
            sb.Append("}}");

            return sb.ToString();
        }
开发者ID:JakeGinnivan,项目名称:TestStack.ConventionTests,代码行数:27,代码来源:MethodInfoDataFormatter.cs


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