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


C# String.TrimStart方法代码示例

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


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

示例1: GetPath

        private static String GetPath(String path, Int32 mode)
        {
            // 处理路径分隔符,兼容Windows和Linux
            var sep = Path.DirectorySeparatorChar;
            var sep2 = sep == '/' ? '\\' : '/';
            path = path.Replace(sep2, sep);

            var dir = "";
            switch (mode)
            {
                case 1:
                    dir = BaseDirectory;
                    break;
                case 2:
                    dir = AppDomain.CurrentDomain.BaseDirectory;
                    break;
                case 3:
                    dir = Environment.CurrentDirectory;
                    break;
                default:
                    break;
            }
            if (dir.IsNullOrEmpty()) return Path.GetFullPath(path);

            // 考虑兼容Linux
            if (!NewLife.Runtime.Mono)
            {
                //if (!Path.IsPathRooted(path))
                //!!! 注意:不能直接依赖于Path.IsPathRooted判断,/和\开头的路径虽然是绝对路径,但是它们不是驱动器级别的绝对路径
                if (path[0] == sep || path[0] == sep2 || !Path.IsPathRooted(path))
                {
                    path = path.TrimStart('~');

                    path = path.TrimStart(sep);
                    path = Path.Combine(dir, path);
                }
            }
            else
            {
                if (!path.StartsWith(dir))
                {
                    // path目录存在,不用再次拼接
                    if (!Directory.Exists(path))
                    {
                        path = path.TrimStart(sep);
                        path = Path.Combine(dir, path);
                    }
                }
            }

            return Path.GetFullPath(path);
        }
开发者ID:tommybiteme,项目名称:X,代码行数:52,代码来源:PathHelper.cs

示例2: Parse

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static SqlBoolean Parse(String s)
        {
            if (null == s)
                // Let Boolean.Parse throw exception
                return new SqlBoolean(Boolean.Parse(s));
            if (s == SQLResource.NullString)
                return SqlBoolean.Null;

            s = s.TrimStart();
            char wchFirst = s[0];
            if (Char.IsNumber(wchFirst) || ('-' == wchFirst) || ('+' == wchFirst))
            {
                return new SqlBoolean(Int32.Parse(s, (IFormatProvider)null));
            }
            else
            {
                return new SqlBoolean(Boolean.Parse(s));
            }
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:22,代码来源:SQLBoolean.cs

示例3: ParseExact

	// Parse a DateTime value, using exact format information.
	public static DateTime ParseExact(String s, String[] formats,
									  IFormatProvider provider,
									  DateTimeStyles style)
			{
				DateTimeFormatInfo info;
				int posn;

				// Validate the parameters.
				if(s == null)
				{
					throw new ArgumentNullException("s");
				}
				if(formats == null)
				{
					throw new ArgumentNullException("formats");
				}
				for(posn = 0; posn < formats.Length; ++posn)
				{
					if(formats[posn] == null)
					{
						throw new ArgumentNullException
							("formats[" + posn.ToString() + "]");
					}
					else if(formats[posn] == String.Empty)
					{
						throw new FormatException(_("Format_Empty"));
					}
				}

				// Get the date time format information from the provider.
				info = DateTimeFormatInfo.GetInstance(provider);

				// Strip white space from the incoming string.
				if((style & DateTimeStyles.AllowLeadingWhite) != 0)
				{
					s = s.TrimStart(null);
				}
				if((style & DateTimeStyles.AllowTrailingWhite) != 0)
				{
					s = s.TrimEnd(null);
				}
				if(s == String.Empty)
				{
					throw new FormatException
						(_("ArgRange_StringNonEmpty"));
				}

				// Process each of the formats in turn.  We may need
				// to recursively re-enter ParseExact if single-letter
				// format characters are used within the list.
				for(posn = 0; posn < formats.Length; ++posn)
				{
					try
					{
						if(formats[posn].Length == 1)
						{
							return ParseExact
								(s, info.GetAllDateTimePatterns
										(formats[posn][0]), info, style);
						}
						else
						{
							return TryParse
								(s, formats[posn], info, style);
						}
					}
					catch(FormatException)
					{
						// Didn't match this format.  Try the next one.
					}
				}

				// If we get here, then we were unable to parse the string.
				throw new FormatException(_("Format_DateTime"));
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:76,代码来源:DateTimeParser.cs

示例4: getNamespace

        private String getNamespace( String codeItem )
        {
            // <%@ Import Namespace="System.Collections.Generic" %>
            if (codeItem.StartsWith( "@" ) == false) return null;
            if (codeItem.IndexOf( "Import" ) < 0) return null;
            if (codeItem.IndexOf( "Namespace" ) < 0) return null;

            String[] arrItem = codeItem.TrimStart( '@' ).Trim().Split( '"' );
            if (arrItem.Length != 3) return null;

            return arrItem[1].Trim();
        }
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:12,代码来源:ContentBlock.cs


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