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


C# String.StartsWith方法代码示例

本文整理汇总了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;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:29,代码来源:DLinqColumnProvider.cs

示例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;
 }
开发者ID:poksme,项目名称:TetriClimber,代码行数:11,代码来源:Constants.cs

示例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);
        }
开发者ID:tommybiteme,项目名称:X,代码行数:52,代码来源:PathHelper.cs

示例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;
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:78,代码来源:BigIntegerToStringTests.cs

示例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;
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:32,代码来源:BigIntegerToStringTests.cs

示例6: IsMagnetLink

 public static bool IsMagnetLink(String magnetLink)
 {
     return magnetLink.StartsWith("magnet:");
 }
开发者ID:alex-kir,项目名称:System.Net.Torrent,代码行数:4,代码来源:MagnetLink.cs

示例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;
		}
开发者ID:nullie,项目名称:mono,代码行数:18,代码来源:CrossAppDomainChannel.cs

示例8: PathToContentPath

 public virtual String PathToContentPath( String path )
 {
     if( path.StartsWith("monkey://data/") ) return "Content/monkey/"+path.Substring( 14 );
     return "";
 }
开发者ID:Beaker13,项目名称:monkeyxamarin,代码行数:5,代码来源:xamarinapp.cs

示例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;
    }
开发者ID:Beaker13,项目名称:monkeyxamarin,代码行数:16,代码来源:xamarinapp.cs

示例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);
            }
开发者ID:JianwenSun,项目名称:cc,代码行数:21,代码来源:WsdlParser.cs

示例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;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:20,代码来源:DLinqColumnProvider.cs

示例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);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:17,代码来源:BigIntegerToStringTests.cs

示例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);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:43,代码来源:AdRotator.cs

示例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
     }
 }
开发者ID:jarneson,项目名称:exiled-toolkit,代码行数:15,代码来源:ToolkitObjects.cs

示例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);
        }
开发者ID:stephentoub,项目名称:corert,代码行数:44,代码来源:CompareInfo.cs


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