草庐IT

AppendFormat

全部标签

c# - 如何在 .NET 3.5 中再次使 StringBuilder 为空?

我有一个循环,我在其中根据特定条件创建一些字符串值。我确实将StringBuilder对象放在循环之外,每次我在循环中有新行时,我都需要清除该行的StringBuilder附加值。我如何清除那些?StringBuildersb=newStringBuilder();foreach(DataRowrowinrecipientsList.Rows){sb.Length=0;sb.Append("");if(row["needsToActivate"]=="1"){sb.AppendFormat("{0}",getUsersWithoutActivationTemplate());}if(r

c# - 如何在 .NET 3.5 中再次使 StringBuilder 为空?

我有一个循环,我在其中根据特定条件创建一些字符串值。我确实将StringBuilder对象放在循环之外,每次我在循环中有新行时,我都需要清除该行的StringBuilder附加值。我如何清除那些?StringBuildersb=newStringBuilder();foreach(DataRowrowinrecipientsList.Rows){sb.Length=0;sb.Append("");if(row["needsToActivate"]=="1"){sb.AppendFormat("{0}",getUsersWithoutActivationTemplate());}if(r

c# - StringBuilder.Append 与 StringBuilder.AppendFormat

我想知道StringBuilder,我有一个问题希望社区能够解释。让我们忘掉代码的可读性,哪些是更快,为什么?StringBuilder.Append:StringBuildersb=newStringBuilder();sb.Append(string1);sb.Append("----");sb.Append(string2);StringBuilder.AppendFormat:StringBuildersb=newStringBuilder();sb.AppendFormat("{0}----{1}",string1,string2); 最佳答案

c# - StringBuilder.Append 与 StringBuilder.AppendFormat

我想知道StringBuilder,我有一个问题希望社区能够解释。让我们忘掉代码的可读性,哪些是更快,为什么?StringBuilder.Append:StringBuildersb=newStringBuilder();sb.Append(string1);sb.Append("----");sb.Append(string2);StringBuilder.AppendFormat:StringBuildersb=newStringBuilder();sb.AppendFormat("{0}----{1}",string1,string2); 最佳答案

ios - 如何使用 appendFormat 在 Swift 中格式化字符串?

我想使用appendFormat将字符串附加到NSMutableString,插入空格以获得我的字符串的最小长度。在objective-c中,我只是使用[text.mutableStringappendFormat:@"%-12s","MyString"];我会得到"MyString"但是在Swift中,我试过了text.mutableString.appendFormat("%-12s","MyString")我得到了一切,但不是“MyString”。出现了一些不知从何而来的随机字符。有谁知道为什么会这样,我应该怎么做?谢谢大家! 最佳答案

c# - 您何时使用 StringBuilder.AppendLine/string.Format 与 StringBuilder.AppendFormat?

最近的questioncameup关于使用String.Format()。我的部分回答包括使用StringBuilder.AppendLine(string.Format(...))的建议。JonSkeet认为这是一个不好的例子,并建议使用AppendLine和AppendFormat的组合。我突然想到,我从来没有真正让自己适应使用这些方法的“首选”方法。我想我可能会开始使用类似以下的东西,但我很想知道其他人使用什么作为“最佳实践”:sbuilder.AppendFormat("{0}line","First").AppendLine();sbuilder.AppendFormat("

c# - 您何时使用 StringBuilder.AppendLine/string.Format 与 StringBuilder.AppendFormat?

最近的questioncameup关于使用String.Format()。我的部分回答包括使用StringBuilder.AppendLine(string.Format(...))的建议。JonSkeet认为这是一个不好的例子,并建议使用AppendLine和AppendFormat的组合。我突然想到,我从来没有真正让自己适应使用这些方法的“首选”方法。我想我可能会开始使用类似以下的东西,但我很想知道其他人使用什么作为“最佳实践”:sbuilder.AppendFormat("{0}line","First").AppendLine();sbuilder.AppendFormat("