本文整理汇总了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);
}
示例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));
}
}
示例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"));
}
示例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();
}