本文整理汇总了C#中String.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:C# String.StartsWith方法的具体用法?C# String.StartsWith怎么用?C# String.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String.StartsWith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMaxLength
// internal to facilitate unit testing
internal static int ProcessMaxLength(Type memberType, String dbType) {
// Only strings and chars that come in from a database have max lengths
if (dbType == null || (memberType != typeof(string) && Misc.RemoveNullableFromType(memberType) != typeof(char)))
return 0;
if (dbType.StartsWith("NText", StringComparison.OrdinalIgnoreCase)) {
return Int32.MaxValue >> 1; // see sql server 2005 spec for ntext
}
if (dbType.StartsWith("Text", StringComparison.OrdinalIgnoreCase)) {
return Int32.MaxValue; // see sql server 2005 spec for text
}
if (dbType.StartsWith("NVarChar(MAX)", StringComparison.OrdinalIgnoreCase)) {
return (Int32.MaxValue >> 1) - 2; // see sql server 2005 spec for nvarchar
}
if (dbType.StartsWith("VarChar(MAX)", StringComparison.OrdinalIgnoreCase)) {
return Int32.MaxValue - 2; // see sql server 2005 spec for varchar
}
Match m = s_varCharRegEx.Match(dbType);
if (m.Success) {
return Int32.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture);
}
return 0;
}
示例2: HexToColor
public static Microsoft.Xna.Framework.Color HexToColor(String hexString)
{
Microsoft.Xna.Framework.Color actColor = Microsoft.Xna.Framework.Color.White;
if (hexString.StartsWith("#") && hexString.Length == 7)
actColor = new Microsoft.Xna.Framework.Color(
int.Parse(hexString.Substring(1,2), System.Globalization.NumberStyles.HexNumber),
int.Parse(hexString.Substring(3,2), System.Globalization.NumberStyles.HexNumber),
int.Parse(hexString.Substring(5,2), System.Globalization.NumberStyles.HexNumber)
);
return actColor;
}
示例3: 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);
}
示例4: PercentFormatter
private static String PercentFormatter(String input, int precision, NumberFormatInfo nfi)
{
String pre = String.Empty;
String post = String.Empty;
if (input.StartsWith(nfi.NegativeSign))
{
input = input.Substring(nfi.NegativeSign.Length);
switch (nfi.PercentNegativePattern)
{
case 0:
pre = nfi.NegativeSign;
post = " " + nfi.PercentSymbol;
break;
case 1:
pre = nfi.NegativeSign;
post = nfi.PercentSymbol;
break;
case 2:
pre = nfi.NegativeSign + nfi.PercentSymbol;
break;
case 3:
pre = nfi.PercentSymbol + nfi.NegativeSign;
break;
case 4:
pre = nfi.PercentSymbol;
post = nfi.NegativeSign;
break;
case 5:
post = nfi.NegativeSign + nfi.PercentSymbol;
break;
case 6:
post = nfi.PercentSymbol + nfi.NegativeSign;
break;
case 7:
pre = nfi.NegativeSign + nfi.PercentSymbol + " ";
break;
case 8:
post = " " + nfi.PercentSymbol + nfi.NegativeSign;
break;
case 9:
pre = nfi.PercentSymbol + " ";
post = nfi.NegativeSign;
break;
case 10:
pre = nfi.PercentSymbol + " " + nfi.NegativeSign;
break;
case 11:
post = nfi.NegativeSign + " " + nfi.PercentSymbol;
break;
}
}
else
{
switch (nfi.PercentPositivePattern)
{
case 0:
post = " " + nfi.PercentSymbol;
break;
case 1:
post = nfi.PercentSymbol;
break;
case 2:
pre = nfi.PercentSymbol;
break;
case 3:
pre = nfi.PercentSymbol + " ";
break;
}
}
if (input != "0")
{
input += "00";
}
return pre + GroupFormatDigits(input, nfi.PercentGroupSeparator, nfi.PercentGroupSizes, nfi.PercentDecimalSeparator, precision) + post;
}
示例5: NumberFormatter
private static String NumberFormatter(String input, int precision, NumberFormatInfo nfi)
{
String pre = String.Empty;
String post = String.Empty;
if (input.StartsWith(nfi.NegativeSign))
{
input = input.Substring(nfi.NegativeSign.Length);
switch (nfi.NumberNegativePattern)
{
case 0:
pre = "(";
post = ")";
break;
case 1:
pre = nfi.NegativeSign;
break;
case 2:
pre = nfi.NegativeSign + " ";
break;
case 3:
post = nfi.NegativeSign;
break;
case 4:
post = " " + nfi.NegativeSign;
break;
}
}
return pre + GroupFormatDigits(input, nfi.NumberGroupSeparator, nfi.NumberGroupSizes, nfi.NumberDecimalSeparator, precision) + post;
}
示例6: IsMagnetLink
public static bool IsMagnetLink(String magnetLink)
{
return magnetLink.StartsWith("magnet:");
}
示例7: CreateMessageSink
// IChannelSender
public virtual IMessageSink CreateMessageSink(String url, Object data, out String uri)
{
uri = null;
if (data != null)
{
// Get the data and then get the sink
CrossAppDomainData cadData = data as CrossAppDomainData;
if (cadData != null && cadData.ProcessID == RemotingConfiguration.ProcessId)
// GetSink creates a new sink if we don't have any (use contexts here later)
return CrossAppDomainSink.GetSink(cadData.DomainID);
}
if (url != null && url.StartsWith(_strName))
throw new NotSupportedException("Can't create a named channel via crossappdomain");
return null;
}
示例8: PathToContentPath
public virtual String PathToContentPath( String path )
{
if( path.StartsWith("monkey://data/") ) return "Content/monkey/"+path.Substring( 14 );
return "";
}
示例9: OpenFile
public override FileStream OpenFile( String path,FileMode mode )
{
if( path.StartsWith( "monkey://internal/" ) ){
IsolatedStorageFile file=IsolatedStorageFile.GetUserStoreForApplication();
if( file==null ) return null;
try{
IsolatedStorageFileStream stream=file.OpenFile( path.Substring( 18 ),mode );
return stream;
}catch( Exception ){
}
}else{
return base.OpenFile( path,mode );
}
return null;
}
示例10: SystemType
internal SystemType(String name, String urlNS, String ns, String assemName)
: base(name, urlNS, ns, ns)
{
Util.Log("SystemType.SystemType name "+name+" ns "+ns+" assemName "+assemName);
Debug.Assert(ns.StartsWith("System", StringComparison.Ordinal), "Invalid System type");
String fullName = ns + '.' + name;
Assembly assem = null;
if (assemName == null)
assem = typeof(string).Assembly;
else
#pragma warning disable 618
assem = Assembly.LoadWithPartialName(assemName, null);
#pragma warning restore 618
if (assem == null)
throw new SUDSParserException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Suds_AssemblyNotFound"), assemName));
_type = assem.GetType(fullName, true);
}
示例11: ProcessIsSortable
internal static bool ProcessIsSortable(Type memberType, String dbType) {
if (dbType == null)
return false;
if (memberType == typeof(string) &&
(dbType.StartsWith("Text", StringComparison.OrdinalIgnoreCase)
|| dbType.StartsWith("NText", StringComparison.OrdinalIgnoreCase))) {
return false;
}
if (memberType == typeof(Binary) && dbType.StartsWith("Image", StringComparison.OrdinalIgnoreCase)) {
return false;
}
if (memberType == typeof(XElement)) {
return false;
}
return true;
}
示例12: ThousandsFormatter
private static String ThousandsFormatter(String input, int precision, NumberFormatInfo nfi)
{
String pre = String.Empty;
if (input.StartsWith(nfi.NegativeSign))
{
input = input.Substring(nfi.NegativeSign.Length);
pre = nfi.NegativeSign;
}
if (input.Equals("0"))
{
input = String.Empty;
}
input = ZeroString(precision - input.Length) + input;
return pre + GroupFormatDigits(input, nfi.NumberGroupSeparator, nfi.NumberGroupSizes, String.Empty, 0);
}
示例13: ResolveAdRotatorUrl
// Helper function adopted from ASP.NET AdRotator class (modified
// slightly)
private String ResolveAdRotatorUrl(String relativeUrl)
{
if (relativeUrl == null)
{
return String.Empty;
}
// check if it is already absolute, or points to another form
if (!UrlPath.IsRelativeUrl(relativeUrl) ||
relativeUrl.StartsWith(Constants.FormIDPrefix, StringComparison.Ordinal))
{
return relativeUrl;
}
// Deal with app relative syntax (e.g. ~/foo)
string tplSourceDir = UrlPath.MakeVirtualPathAppAbsolute(TemplateSourceDirectory);
// For the AdRotator, use the AdvertisementFile directory as the
// base, and fall back to the page/user control location as the
// base.
String absoluteFile = UrlPath.Combine(tplSourceDir,
AdvertisementFile);
String fileDirectory = UrlPath.GetDirectory(absoluteFile);
String baseUrl = String.Empty;
if (fileDirectory != null)
{
baseUrl = fileDirectory;
}
if (baseUrl.Length == 0)
{
baseUrl = tplSourceDir;
}
if (baseUrl.Length == 0)
{
return relativeUrl;
}
// make it absolute
return UrlPath.Combine(baseUrl, relativeUrl);
}
示例14: EvaluateMod
private void EvaluateMod(String lMod)
{
if (lMod.StartsWith("Adds"))
{
// Probably Damage Mod
}
else if (lMod.StartsWith("+"))
{
// Flat bonus to something or Life/Mana on hit/kill
}
else if (lMod.Contains("%"))
{
// Percent bonus to something
}
}
示例15: IsPrefix
////////////////////////////////////////////////////////////////////////
//
// IsPrefix
//
// Determines whether prefix is a prefix of string. If prefix equals
// String.Empty, true is returned.
//
////////////////////////////////////////////////////////////////////////
public unsafe virtual bool IsPrefix(String source, String prefix, CompareOptions options)
{
if (source == null || prefix == null)
{
throw new ArgumentNullException((source == null ? nameof(source) : nameof(prefix)),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
if (prefix.Length == 0)
{
return (true);
}
if (source.Length == 0)
{
return false;
}
if (options == CompareOptions.OrdinalIgnoreCase)
{
return source.StartsWith(prefix, StringComparison.OrdinalIgnoreCase);
}
if (options == CompareOptions.Ordinal)
{
return source.StartsWith(prefix, StringComparison.Ordinal);
}
if ((options & ValidIndexMaskOffFlags) != 0)
{
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
return StartsWith(source, prefix, options);
}