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


C# String.IndexOf方法代码示例

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


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

示例1: Stylesheet

 public Stylesheet(String stylesheet)
 {
     char currentChar = '\0';
     StringBuilder buffer = new StringBuilder();
     for (int i = 0, j = 0; i < stylesheet.Length; i++, j++)
     {
         currentChar = stylesheet[i];
         switch (currentChar)
         {
             case ' ':
                 continue;
             case '{':
                 {
                     int endIndex = stylesheet.IndexOf('}', i);
                     String block = stylesheet.Substring(i, endIndex - i);
                     Selector selector = new Selector(buffer.ToString().Trim(), block);
                     this.selectors.Add(selector);
                     i = endIndex - 1;
                     buffer.Clear();
                     continue;
                 }
             default:
                 buffer.Append(currentChar);
                 break;
         }
     }
 }
开发者ID:krikelin,项目名称:SpiderView,代码行数:27,代码来源:CSS.cs

示例2: while

	// Validate a qualified identifier.
	private static void ValidateQualifiedIdentifier
				(String value, bool canBeNull)
			{
				if(value == null)
				{
					if(!canBeNull)
					{
						throw new ArgumentException
							(S._("Arg_InvalidIdentifier"));
					}
				}
				else
				{
					int posn = 0;
					int index;
					String component;
					while((index = value.IndexOf('.', posn)) != -1)
					{
						component = value.Substring(posn, index - posn);
						ValidateIdentifier(component);
						posn = index + 1;
					}
					component = value.Substring(posn);
					ValidateIdentifier(component);
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:Validator.cs

示例3: CheckSearchPattern

 // ".." can only be used if it is specified as a part of a valid File/Directory name. We disallow
 //  the user being able to use it to move up directories. Here are some examples eg 
 //    Valid: a..b  abc..d
 //    Invalid: ..ab   ab..  ..   abc..d\abc..
 //
 internal static void CheckSearchPattern(String searchPattern)
 {
     for (int index = 0; (index = searchPattern.IndexOf("..", index, StringComparison.Ordinal)) != -1; index += 2)
     {
         // Terminal ".." or "..\". File and directory names cannot end in "..".
         if (index + 2 == searchPattern.Length || 
             IsDirectorySeparator(searchPattern[index + 2]))
         {
             throw new ArgumentException(SR.Arg_InvalidSearchPattern, "searchPattern");
         }
     }
 }
开发者ID:brianjsykes,项目名称:corefx,代码行数:17,代码来源:PathHelpers.Windows.cs

示例4: AccessingLoginPage

        internal static bool AccessingLoginPage(HttpContext context, String loginUrl) {
            if (String.IsNullOrEmpty(loginUrl)) {
                return false;
            }

            loginUrl = GetCompleteLoginUrl(context, loginUrl);
            if (String.IsNullOrEmpty(loginUrl)) {
                return false;
            }

            // Ignore query string
            int iqs = loginUrl.IndexOf('?');
            if (iqs >= 0) {
                loginUrl = loginUrl.Substring(0, iqs);
            }

            String requestPath = context.Request.Path;

            if (StringUtil.EqualsIgnoreCase(requestPath, loginUrl)) {
                return true;
            }

            // It could be that loginUrl in config was UrlEncoded (ASURT 98932)
            if (loginUrl.IndexOf('%') >= 0) {
                String decodedLoginUrl;
                // encoding is unknown try UTF-8 first, then request encoding

                decodedLoginUrl = HttpUtility.UrlDecode(loginUrl);
                if (StringUtil.EqualsIgnoreCase(requestPath, decodedLoginUrl)) {
                    return true;
                }

                decodedLoginUrl = HttpUtility.UrlDecode(loginUrl, context.Request.ContentEncoding);
                if (StringUtil.EqualsIgnoreCase(requestPath, decodedLoginUrl)) {
                    return true;
                }
            }

            return false;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:40,代码来源:AuthenticationConfig.cs

示例5: WebProxy

	public WebProxy(String Address)
			{
				if(Address != null)
				{
					if(Address.IndexOf("://") == -1)
					{
						address = new Uri("http://" + Address);
					}
					else
					{
						address = new Uri(Address);
					}
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:14,代码来源:WebProxy.cs

示例6: LocateNextSelectedDate

 private int LocateNextSelectedDate(String webCalendarHtml, int startingIndex)
 {
     int tagBeginIndex = startingIndex;
     do
     {
         tagBeginIndex = webCalendarHtml.IndexOf(_selectedDateSearchCellTag, tagBeginIndex, StringComparison.Ordinal);
         if (tagBeginIndex >= 0)
         {
             int tagEndIndex = webCalendarHtml.IndexOf(">", tagBeginIndex + _bgColorInsertionPointInPattern, StringComparison.Ordinal);
             Debug.Assert(tagEndIndex >= 0);
             String tagComplete = webCalendarHtml.Substring(tagBeginIndex, tagEndIndex-tagBeginIndex+1);
             if (tagComplete.IndexOf(_selectedDateSearchAttr, StringComparison.Ordinal) >= 0)
             {
                 return tagBeginIndex;
             }
             else
             {
                 tagBeginIndex += _bgColorInsertionPointInPattern;
             }
         }
     }
     while (tagBeginIndex >= 0);
     return -1;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:24,代码来源:HtmlCalendarAdapter.cs

示例7: SoapFault

	internal SoapFault(SerializationInfo info, StreamingContext context)
			{
				faultCode = info.GetStringIgnoreCase("faultcode");
				if(faultCode != null)
				{
					int posn = faultCode.IndexOf(':');
					if(posn != -1)
					{
						faultCode = faultCode.Substring(posn + 1);
					}
				}
				faultString = info.GetStringIgnoreCase("faultstring");
				faultActor = info.GetStringIgnoreCase("faultactor");
				serverFault = info.GetValueIgnoreCase("detail", typeof(Object));
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:15,代码来源:SoapFault.cs

示例8: ExtractValueFromContentDispositionHeader

        private String ExtractValueFromContentDispositionHeader(String l, int pos, String name) {
            String pattern = " " + name + "=";
            int i1 = CultureInfo.InvariantCulture.CompareInfo.IndexOf(l, pattern, pos, CompareOptions.IgnoreCase);
            if (i1 < 0) {
                pattern = ";" + name + "=";
                i1 = CultureInfo.InvariantCulture.CompareInfo.IndexOf(l, pattern, pos, CompareOptions.IgnoreCase);
                if (i1 < 0) {
                    pattern = name + "=";
                    i1 = CultureInfo.InvariantCulture.CompareInfo.IndexOf(l, pattern, pos, CompareOptions.IgnoreCase);
                }
            }
            if (i1 < 0)
                return null;
            i1 += pattern.Length;
            if (i1 >= l.Length)
                return String.Empty;

            if (l[i1] == '"') {
                i1 += 1;
                int i2 = l.IndexOf('"', i1);
                if (i2 < 0)
                    return null;
                if (i2 == i1)
                    return String.Empty;

                return l.Substring(i1, i2-i1);
            }
            else {
                int i2 = l.IndexOf(';', i1);
                if (i2 < 0)
                    i2 = l.Length;

                return l.Substring(i1, i2-i1).Trim();
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:35,代码来源:MultipartContentParser.cs

示例9: sendCommand

            /// <summary>
            /// sendCommand
            /// </summary>
            /// <param name="command"></param>
            private void sendCommand(String command)
            {
                int l_iRetval = 0;

                if (this.verboseDebugging)
                {
                    if (command.IndexOf("PASS ") >= 0)
                    {
                        // don't show password in message area
                        // show only *
                        showMessage("PASS [*** hidden ***]", false);
                    }
                    else
                    {
                        showMessage(command, false);
                    }
                }

                try
                {
                    Byte[] cmdBytes = Encoding.ASCII.GetBytes((command.Trim() + "\r\n").ToCharArray());
                    l_iRetval = clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
                    this.readResponse();
                }
                catch (Exception ex)
                {
                    throw new IOException(ex.Message);
                }
            }
开发者ID:paulwangxp,项目名称:MDWorkStation4PC,代码行数:33,代码来源:LightFTPClient.cs

示例10: GetMethodName

 private static String GetMethodName(String methodName)
 {
     int startIndex = methodName.IndexOf(" ") + 1;
     int endIndex = methodName.IndexOf("(");
     return methodName.Substring(startIndex, endIndex - startIndex);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:6,代码来源:RuntimeReflectionExtensionTests.cs

示例11: GetMethodParameters

        private static Type[] GetMethodParameters(String methodName)
        {
            int startIndex = methodName.IndexOf("(") + 1;
            int endIndex = methodName.IndexOf(")");
            if (endIndex <= startIndex)
                return new Type[0];

            String[] parameters = methodName.Substring(startIndex, endIndex - startIndex).Split(',');
            List<Type> parameterList = new List<Type>();
            foreach (String parameter in parameters)
                parameterList.Add(Type.GetType(parameter.Trim()));
            return parameterList.ToArray();
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:13,代码来源:RuntimeReflectionExtensionTests.cs

示例12: SetDescription

        /*
         * SetDescription()
         *
         * Produces a human-readable description for a set string.
         */
        internal static String SetDescription(String set) {
            int mySetLength = set[SETLENGTH];
            int myCategoryLength = set[CATEGORYLENGTH];
            int myEndPosition = SETSTART + mySetLength + myCategoryLength;

            StringBuilder desc = new StringBuilder("[");

            int index = SETSTART;
            char ch1;
            char ch2;

            if (IsNegated(set)) 
                desc.Append('^');

            while (index < SETSTART + set[SETLENGTH]) {
                ch1 = set[index];
                if (index + 1 < set.Length)
                    ch2 = (char)(set[index + 1] - 1);
                else
                    ch2 = Lastchar;

                desc.Append(CharDescription(ch1));

                if (ch2 != ch1) {
                    if (ch1 + 1 != ch2)
                        desc.Append('-');
                    desc.Append(CharDescription(ch2));
                }
                index += 2;
            }

            while (index < SETSTART + set[SETLENGTH] + set[CATEGORYLENGTH]) {
                ch1 = set[index];
                if (ch1 == 0) {
                    bool found = false;
                    
                    int lastindex = set.IndexOf(GroupChar, index+1);
                    string group = set.Substring(index,lastindex-index + 1);

                    IDictionaryEnumerator en = _definedCategories.GetEnumerator();
                    while(en.MoveNext()) {
                        if (group.Equals(en.Value)) {
                            if ((short) set[index+1] > 0)
                                desc.Append("\\p{" + en.Key + "}");
                            else
                                desc.Append("\\P{" + en.Key + "}");

                            found = true;
                            break;
                        }
                    }

                    if (!found) {
                        if (group.Equals(Word))
                            desc.Append("\\w");
                        else if (group.Equals(NotWord))
                            desc.Append("\\W");
                        else 
                            Debug.Assert(false, "Couldn't find a goup to match '" + group + "'");
                    }
                    
                    index = lastindex;
                }
                else {
                    desc.Append(CategoryDescription(ch1));
                }
                    
                index++;
            }

            if (set.Length > myEndPosition) {
                desc.Append('-');
                desc.Append(SetDescription(set.Substring(myEndPosition)));
            }

            desc.Append(']');

            return desc.ToString();
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:84,代码来源:regexcharclass.cs

示例13: CheckSearchPattern

 // ".." can only be used if it is specified as a part of a valid File/Directory name. We disallow
 //  the user being able to use it to move up directories. Here are some examples eg 
 //    Valid: a..b  abc..d
 //    Invalid: ..ab   ab..  ..   abc..d\abc..
 //
 internal static void CheckSearchPattern(String searchPattern)
 {
     int index;
     while ((index = searchPattern.IndexOf("..", StringComparison.Ordinal)) != -1) {
             
          if (index + 2 == searchPattern.Length) // Terminal ".." . Files names cannot end in ".."
             throw new ArgumentException(Environment.GetResourceString("Arg_InvalidSearchPattern"));
         
          if ((searchPattern[index+2] ==  DirectorySeparatorChar)
             || (searchPattern[index+2] == AltDirectorySeparatorChar))
             throw new ArgumentException(Environment.GetResourceString("Arg_InvalidSearchPattern"));
         
         searchPattern = searchPattern.Substring(index + 2);
     }
 }
开发者ID:sushihangover,项目名称:playscript,代码行数:20,代码来源:Path.cs

示例14: CheckForRedirectedClientType

            } // CheckForWellKnownServiceEntryOfType


            // returns true if activation for the type has been redirected.
            private bool CheckForRedirectedClientType(String typeName, String asmName)
            {
                // if asmName has version information, remove it.
                int index = asmName.IndexOf(",");
                if (index != -1)
                    asmName = asmName.Substring(0, index);

                return 
                    (QueryRemoteActivate(typeName, asmName) != null) ||
                    (QueryConnect(typeName, asmName) != null);
            } // CheckForRedirectedClientType
开发者ID:REALTOBIZ,项目名称:mono,代码行数:15,代码来源:configuration.cs

示例15: GetEmbededNullStringLengthAnsi

 private static int GetEmbededNullStringLengthAnsi(String s) {
     int n = s.IndexOf('\0');
     if (n > -1) {
         String left = s.Substring(0, n);
         String right = s.Substring(n+1);
         return GetPInvokeStringLength(left) + GetEmbededNullStringLengthAnsi(right) + 1;
     }
     else {
         return GetPInvokeStringLength(s);
     }
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:11,代码来源:NativeMethodsCLR.cs


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