当前位置: 首页>>代码示例>>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;未经允许,请勿转载。