當前位置: 首頁>>代碼示例>>C#>>正文


C# StringBuilder.Insert方法代碼示例

本文整理匯總了C#中System.StringBuilder.Insert方法的典型用法代碼示例。如果您正苦於以下問題:C# StringBuilder.Insert方法的具體用法?C# StringBuilder.Insert怎麽用?C# StringBuilder.Insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.StringBuilder的用法示例。


在下文中一共展示了StringBuilder.Insert方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: V_Concat

		private void V_Concat( int total )
		{
			Utl.Assert( total >= 2 );

			do
			{
				var top = Top;
				int n = 2;
				var lhs = Stack[top.Index - 2];
				var rhs = Stack[top.Index - 1];
				if(!(lhs.V.TtIsString() || lhs.V.TtIsNumber()) || !ToString(ref rhs.V))
				{
					if( !CallBinTM( lhs, rhs, lhs, TMS.TM_CONCAT ) )
						G_ConcatError( lhs, rhs );
				}
				else if(rhs.V.SValue().Length == 0) {
					ToString(ref lhs.V);
				}
				else if(lhs.V.TtIsString() && lhs.V.SValue().Length == 0) {
					lhs.V.SetObj(ref rhs.V);
				}
				else
				{
					StringBuilder sb = new StringBuilder();
					n = 0;
					for( ; n<total; ++n )
					{
						var cur = Stack[top.Index-(n+1)];

						if(cur.V.TtIsString())
							sb.Insert(0, cur.V.SValue());
						else if(cur.V.TtIsNumber())
							sb.Insert(0, cur.V.NValue.ToString());
						else
							break;
					}

					var dest = Stack[top.Index - n];
					dest.V.SetSValue(sb.ToString());
				}
				total -= n-1;
				Top = Stack[Top.Index - (n-1)];
			} while( total > 1 );
		}
開發者ID:Jornason,項目名稱:UniLua,代碼行數:44,代碼來源:VM.cs

示例2: ResizeLine

        private System.String ResizeLine(TextPaint textPaint, string line, int availableWidth)
        {
            var texteWidth = MeasureTextWidth (textPaint, line);
            var lastDeletePos = -1;

            var builder = new StringBuilder (line);
            while (texteWidth > availableWidth && builder.Length () > 0) {
                lastDeletePos = builder.Length () / 2;
                builder.DeleteCharAt (builder.Length () / 2);
                var textToMeasure = builder.ToString () + Ellipsis;
                texteWidth = MeasureTextWidth (textPaint, textToMeasure);
            }

            if (lastDeletePos > -1)
                builder.Insert (lastDeletePos, Ellipsis);
            return builder.ToString ();
        }
開發者ID:RasaCosmin,項目名稱:DropboxApp,代碼行數:17,代碼來源:AutoResizeTextView.cs

示例3: GetXPath

 public static string GetXPath(XmlNode node)
 {
     System.StringBuilder builder = new System.StringBuilder();
     while (node != null)
     {
         switch (node.NodeType)
         {
             case XmlNodeType.Attribute:
                 builder.Insert(0, "/@" + node.Name);
                 node = ((XmlAttribute)node).OwnerElement;
                 break;
             case XmlNodeType.Element:
                 if (node.Attributes["PropertyName"] != null)
                     builder.Insert(0, "/" + node.Name + "[@PropertyName='" + node.Attributes["PropertyName"].Value + "']");
                 else
                 {
                     int index = Utility.FindElementIndex((XmlElement)node);
                     builder.Insert(0, "/" + node.Name + "[" + index + "]");
                 }
                 node = node.ParentNode;
                 break;
             case XmlNodeType.Document:
                 return builder.ToString();
             default:
                 throw new ArgumentException("Only elements and attributes are supported");
         }
     }
     throw new ArgumentException("Node was not in a document");
 }
開發者ID:priestofpsi,項目名稱:theDiary-Common-Framework,代碼行數:29,代碼來源:Utility.cs

示例4: Save

        /// <summary>
        /// Save the output to the given file
        /// If the file already exists, don't overwrite it
        /// </summary>
        /// <param name="fileName"></param>
        public static void Save(string fileName)
        {
            try
            {
                string configFile = GetConfigFileName(fileName);

#if REPLACEORIGINAL
            StringBuilder original = new StringBuilder();
            
            string str;
            // read the original file
            using (StreamReader sr = new StreamReader(configFile))
                str = sr.ReadToEnd();

            original.Append(str);
            // find the delimeters and delete the old configuration
            int start = str.IndexOf(Resources.Configuration_StartDelimeter);
            if (start >= 0)
            {
                int end = str.LastIndexOf(Resources.Configuration_EndDelimeter) + Resources.Configuration_EndDelimeter.Length;
                original.Remove(start, end - start);
            }
            else
            {
                start = str.IndexOf("<xs:schema");
            }

            // insert the new configuration
            string config = Output();
            original.Insert(start, config);

            // write it out
            using (StreamWriter sw = new StreamWriter(configFile, false))
                sw.Write(original.ToString());
#else
                if (!File.Exists(configFile))
                    Serializer.SerializeToFile<Configuration>(m_configuration, configFile);

#endif
            }
            catch (Exception ex)
            {
                string message = string.Format("Error saving XmlToClasses configuration file {0}. See Inner Exception below for details", fileName);
                throw new Exception(message, ex);
            }
        }
開發者ID:nujmail,項目名稱:xsd-to-classes,代碼行數:51,代碼來源:Configuration.cs


注:本文中的System.StringBuilder.Insert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。