本文整理汇总了C#中System.Text.StringBuilder.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.StringBuilder.Insert方法的具体用法?C# System.Text.StringBuilder.Insert怎么用?C# System.Text.StringBuilder.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.StringBuilder
的用法示例。
在下文中一共展示了System.Text.StringBuilder.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
footer = Sitecore.Context.Database.GetItem(footerItemPath);
//Main Menu items
List<PageSummaryItem> items = footer.Mainlinks.ListItems.ConvertAll(x => new PageSummaryItem(x));
System.Text.StringBuilder markupBuilder = new System.Text.StringBuilder();
int childcounter = 0;
foreach (PageSummaryItem child in items)
{
if (!string.IsNullOrEmpty(child.NavigationTitle.Text))
{
markupBuilder.AppendFormat(@"<li{2}><a href=""{0}"">{1}</a></li>", child.Url, child.NavigationTitle.Rendered, childcounter == 0 ? @" class=""first""" : "");
childcounter++;
}
}
if (markupBuilder.Length > 0)
{
markupBuilder.Insert(0, "<ul>");
markupBuilder.Insert(0, "<nav>");
markupBuilder.AppendFormat(@"<li><a href=""{0}"" class=""external"" target=""_blank"">{1}</a></li>", Settings.CareersLink, Translate.Text("Careers"));
markupBuilder.Append("</ul>");
markupBuilder.Append("</nav>");
markup = markupBuilder.ToString();
}
//Submenu items
List<PageSummaryItem> subitems = footer.Sublinks.ListItems.ConvertAll(x => new PageSummaryItem(x));
System.Text.StringBuilder markupBuilderSub = new System.Text.StringBuilder();
childcounter = 0;
//Set Link to Mobile Site -if we are using a Mobile device.
if (SitecoreHelper.GetDeviceFromCookie().Equals(Settings.MobileDevice, StringComparison.OrdinalIgnoreCase))
{
string startPath = Sitecore.Context.Site.StartPath.ToString();
var homeItem = Sitecore.Context.Database.GetItem(startPath);
var options = new UrlOptions { AlwaysIncludeServerUrl = true, AddAspxExtension = false, LanguageEmbedding = LanguageEmbedding.Never };
var homeUrl = LinkManager.GetItemUrl(homeItem, options);
//Set return to main site link
markupBuilderSub.AppendFormat(@"<li><a href=""{0}"">{1}</a></li>", homeUrl + "?sc_device=mobile&persisted=true", Translate.Text("Mobile Site"));
childcounter++;
}
foreach (PageSummaryItem child in subitems)
{
if (!string.IsNullOrEmpty(child.NavigationTitle.Text))
{
string url = Sitecore.Links.LinkManager.GetItemUrl(child.InnerItem);
markupBuilderSub.AppendFormat(@"<li><a href=""{0}"">{1}</a></li>", url, child.NavigationTitle.Rendered);
childcounter++;
}
}
if (markupBuilderSub.Length > 0)
{
subMenuMarkup = markupBuilderSub.ToString();
}
}
示例2: ListToString
/// <summary>
/// Returns a string representation of this IList.
/// </summary>
/// <remarks>
/// The string representation is a list of the collection's elements in the order
/// they are returned by its IEnumerator, enclosed in square brackets ("[]").
/// The separator is a comma followed by a space i.e. ", ".
/// </remarks>
/// <param name="coll">Collection whose string representation will be returned</param>
/// <returns>A string representation of the specified collection or "null"</returns>
public static string ListToString(IList coll)
{
StringBuilder sb = new StringBuilder();
if (coll != null)
{
sb.Append("[");
for (int i = 0; i < coll.Count; i++)
{
if (i > 0)
sb.Append(", ");
object element = coll[i];
if (element == null)
sb.Append("null");
else if (element is IDictionary)
sb.Append(DictionaryToString((IDictionary)element));
else if (element is IList)
sb.Append(ListToString((IList)element));
else
sb.Append(element.ToString());
}
sb.Append("]");
}
else
sb.Insert(0, "null");
return sb.ToString();
}
示例3: ToString
/// <summary>
/// Converts a number to System.String.
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public static System.String ToString(long number)
{
System.Text.StringBuilder s = new System.Text.StringBuilder();
if (number == 0)
{
s.Append("0");
}
else
{
if (number < 0)
{
s.Append("-");
number = -number;
}
while (number > 0)
{
char c = digits[(int)number % 36];
s.Insert(0, c);
number = number / 36;
}
}
return s.ToString();
}
示例4: GetTargetStringLiteralFromANTLRStringLiteral
/** Convert from an ANTLR string literal found in a grammar file to
* an equivalent string literal in the target language. For Java, this
* is the translation 'a\n"' -> "a\n\"". Expect single quotes
* around the incoming literal. Just flip the quotes and replace
* double quotes with \"
*/
public override string GetTargetStringLiteralFromANTLRStringLiteral( CodeGenerator generator,
string literal )
{
literal = literal.Replace( "\"", "\\\"" );
StringBuilder buf = new StringBuilder( literal );
buf[0] = '"';
buf[literal.Length - 1] = '"';
buf.Insert( 0, '@' );
return buf.ToString();
}
示例5: convertBase10toN
//True Function
public static string convertBase10toN(int base10, int baseN)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while (base10 > 0)
{
int d = base10 % baseN;
sb.Insert(0, d);
base10 = base10 / baseN;
}
return sb.ToString();
}
示例6: GetFullItemPath
public static string GetFullItemPath(IWebDavStoreCollection collection)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
var current = collection;
while (current != null)
{
sb.Insert(0, current.Name);
sb.Append("/");
current = current.ParentCollection;
}
sb.Length -= 1;
return sb.ToString();
}
示例7: RenderNumber
private static string RenderNumber(long value, int length)
{
System.Text.StringBuilder numberBuilder = new System.Text.StringBuilder(value.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo));
//string field = value.ToString("x");
if (numberBuilder.Length > length)
return numberBuilder.ToString().Substring(numberBuilder.Length - length);
while (numberBuilder.Length < length)
numberBuilder.Insert(0, "0");
//field = "0" + field;
return numberBuilder.ToString();
}
示例8: ToString
public override string ToString()
{
System.Text.StringBuilder from = new System.Text.StringBuilder()
.AppendLine("\t\t\t\t" + Format.Formatting.FormatForFromClause(table));
foreach (Expressions.JoinExpression join in joins)
{
from.AppendLine(join.ToString());
}
from
.Insert(0, "FROM" + System.Environment.NewLine);
return from.ToString();
}
示例9: DictionaryToString
/// <summary>
/// Returns a string representation of this IList.
/// </summary>
/// <remarks>
/// The string representation is a list of the collection's elements in the order
/// they are returned by its IEnumerator, enclosed in square brackets ("[]").
/// The separator is a comma followed by a space i.e. ", ".
/// </remarks>
/// <param name="coll">Collection whose string representation will be returned</param>
/// <returns>A string representation of the specified collection or "null"</returns>
public static string DictionaryToString(IDictionary dict)
{
StringBuilder sb = new StringBuilder();
if (dict != null)
{
sb.Append("{");
int i = 0;
foreach (DictionaryEntry e in dict)
{
if (i > 0)
{
sb.Append(", ");
}
sb.AppendFormat("{0}={1}", e.Key.ToString(), e.Value.ToString());
i++;
}
sb.Append("}");
}
else
sb.Insert(0, "null");
return sb.ToString();
}
示例10: indent
/// <summary>Indent a String that contains newlines. </summary>
public static System.String indent(System.String ident, System.String instr)
{
System.Text.StringBuilder tgt = new System.Text.StringBuilder(instr);
char eolChar = eol[0];
int i = tgt.Length;
while (--i > 0)
{
if (tgt[i] == eolChar)
tgt.Insert(i + 1, ident);
}
return ident + tgt.ToString();
}
示例11: QuotedPrintable2Unicode
/// <summary>
/// Decode rfc 2047 definition of quoted-printable
/// </summary>
/// <param name="enc"><see cref="System.Text.Encoding" /> to use</param>
/// <param name="orig"><see cref="System.String" /> to decode</param>
/// <returns>the decoded <see cref="System.String" /></returns>
public static System.String QuotedPrintable2Unicode ( System.Text.Encoding enc, System.String orig ) {
if ( enc==null || orig==null )
return orig;
System.Text.StringBuilder decoded = new System.Text.StringBuilder(orig);
int bytecount=0, offset=0;
System.Byte[] ch = new System.Byte[24];
for ( int i=0, total=decoded.Length; i<total; ) {
// Possible encoded byte
if ( decoded[i] == '=' && (total-i)>2 ) {
System.String hex = decoded.ToString(i+1, 2);
// encoded byte
if ( IsValidHexChar(hex[0]) && IsValidHexChar(hex[1]) ) {
ch[bytecount++] = System.Convert.ToByte(hex, 16);
offset+=3;
i+=3;
// soft line break
} else if ( hex==ABNF.CRLF ) {
offset+=3;
i+=3;
// there shouldn't be a '=' without being encoded, so we remove it
} else {
offset++;
i++;
}
// Replace chars with decoded bytes if we have finished the series of encoded bytes
// or have filled the buffer.
if ( offset>0 && (bytecount==24 || i==total || (total-i)<3 || decoded[i]!='=') ) {
i-=offset;
total-=offset;
decoded.Remove(i, offset);
if ( bytecount>0 ) {
System.String decodedItem = enc.GetString(ch, 0, bytecount);
decoded.Insert(i, decodedItem);
i+=decodedItem.Length;
total+=decodedItem.Length;
}
bytecount=0;
offset=0;
}
} else {
i++;
}
}
return decoded.ToString();
}
示例12: TimeToString
/// <summary> Converts a millisecond time to a string suitable for indexing.</summary>
/// <throws> RuntimeException if the time specified in the </throws>
/// <summary> method argument is negative, that is, before 1970
/// </summary>
public static System.String TimeToString(long time)
{
if (time < 0)
throw new System.SystemException("time too early");
System.String s = SupportClass.Number.ToString(time, SupportClass.Number.MAX_RADIX);
if (s.Length > DATE_LEN)
throw new System.SystemException("time too late");
// Pad with leading zeros
if (s.Length < DATE_LEN)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(s);
while (sb.Length < DATE_LEN)
sb.Insert(0, 0);
s = sb.ToString();
}
return s;
}
示例13: GetProperties
private Dictionary<string, object> GetProperties(Node node, IEnumerable<string> properties)
{
var result = new Dictionary<string,object>();
var errors = new System.Text.StringBuilder();
foreach(var pname in properties) {
var property = node[pname];
if (property != null) result[pname] = property;
else errors.Append(pname).Append(", ");
}
if (errors.Length > 0) {
errors.Length -= 2;
errors.Insert(0, "Undefined properties for "+node.GetType().Name+": ");
errors.Append(". (line:\"").Append(node.CodeElement.InputStream).Append("\")");
throw new System.ArgumentException(errors.ToString());
}
return result;
}
示例14: GetDebugTargetInfo
//.........这里部分代码省略.........
string startProgram = StartProgram;
if (!string.IsNullOrEmpty(startProgram))
info.bstrExe = startProgram;
}
else
// property is either null or "Project"
// we're ignoring "URL" for now
{
string outputType = project.GetProjectProperty(ProjectFileConstants.OutputType, false);
if (forLaunch && 0 == string.Compare("library", outputType, StringComparison.OrdinalIgnoreCase))
throw new ClassLibraryCannotBeStartedDirectlyException();
info.bstrExe = this.project.GetOutputAssembly(this.configCanonicalName);
}
property = GetConfigurationProperty("RemoteDebugMachine", false);
if (property != null && property.Length > 0)
{
info.bstrRemoteMachine = property;
}
bool isRemoteDebug = (info.bstrRemoteMachine != null);
property = GetConfigurationProperty("StartWorkingDirectory", false);
if (string.IsNullOrEmpty(property))
{
// 3273: aligning with C#
info.bstrCurDir = Path.GetDirectoryName(this.project.GetOutputAssembly(this.configCanonicalName));
}
else
{
if (isRemoteDebug)
{
info.bstrCurDir = property;
}
else
{
string fullPath;
if (Path.IsPathRooted(property))
{
fullPath = property;
}
else
{
// use project folder as a base part when computing full path from given relative
var currentDir = Path.GetDirectoryName(this.project.GetOutputAssembly(this.configCanonicalName));
fullPath = Path.Combine(currentDir, property);
}
if (!Directory.Exists(fullPath))
throw new WorkingDirectoryNotExistsException(fullPath);
info.bstrCurDir = fullPath;
}
}
property = GetConfigurationProperty("StartArguments", false);
if (!string.IsNullOrEmpty(property))
{
info.bstrArg = property;
}
info.fSendStdoutToOutputWindow = 0;
property = GetConfigurationProperty("EnableUnmanagedDebugging", false);
if (property != null && string.Compare(property, "true", StringComparison.OrdinalIgnoreCase) == 0)
{
//Set the unmanged debugger
//TODO change to vsconstant when it is available in VsConstants. It should be guidCOMPlusNativeEng
info.clsidCustom = new Guid("{92EF0900-2251-11D2-B72E-0000F87572EF}");
}
else
{
//Set the managed debugger
info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine;
}
info.grfLaunch = grfLaunch;
bool isConsoleApp = string.Compare("exe",
project.GetProjectProperty(ProjectFileConstants.OutputType, false),
StringComparison.OrdinalIgnoreCase) == 0;
bool noDebug = ((uint)(((__VSDBGLAUNCHFLAGS)info.grfLaunch) & __VSDBGLAUNCHFLAGS.DBGLAUNCH_NoDebug)) != 0;
// Do not use cmd.exe to get "Press any key to continue." when remote debugging
if (isConsoleApp && noDebug && !isRemoteDebug)
{
// VSWhidbey 573404: escape the characters ^<>& so that they are passed to the application rather than interpreted by cmd.exe.
System.Text.StringBuilder newArg = new System.Text.StringBuilder(info.bstrArg);
newArg.Replace("^", "^^")
.Replace("<", "^<")
.Replace(">", "^>")
.Replace("&", "^&");
newArg.Insert(0, "\" ");
newArg.Insert(0, info.bstrExe);
newArg.Insert(0, "/c \"\"");
newArg.Append(" & pause\"");
string newExe = Path.Combine(Environment.SystemDirectory, "cmd.exe");
info.bstrArg = newArg.ToString();
info.bstrExe = newExe;
}
return info;
}
示例15: toOctal
// own Escape functionfor ocatl numbers because missing in C#
protected static string toOctal(char c)
{
int ic= c;
System.Text.StringBuilder tmp= new System.Text.StringBuilder();
while (ic>0)
{
tmp.Insert(0,ic%8);
ic= ((int)ic/8);
}
return tmp.ToString();
}