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


C# String.IndexOfAny方法代码示例

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


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

示例1: MatchSpecifiedWords

        internal bool MatchSpecifiedWords(String target, bool checkWordBoundary, ref int matchLength) {
            int valueRemaining = Value.Length - Index;
            matchLength = target.Length;

            if (matchLength > valueRemaining || m_info.Compare(Value, Index, matchLength, target, 0, matchLength, CompareOptions.IgnoreCase) !=0) {
                // Check word by word
                int targetPosition = 0;                 // Where we are in the target string
                int thisPosition = Index;         // Where we are in this string
                int wsIndex = target.IndexOfAny(WhiteSpaceChecks, targetPosition);
                if (wsIndex == -1) {
                    return false;
                }
                do {
                    int segmentLength = wsIndex - targetPosition;
                    if (thisPosition >= Value.Length - segmentLength) { // Subtraction to prevent overflow.
                        return false;
                    }
                    if (segmentLength == 0) {
                        // If segmentLength == 0, it means that we have leading space in the target string.
                        // In that case, skip the leading spaces in the target and this string.
                        matchLength--;
                    } else {
                        // Make sure we also have whitespace in the input string
                        if (!Char.IsWhiteSpace(Value[thisPosition + segmentLength])) {
                            return false;
                        }
                        if (m_info.Compare(Value, thisPosition, segmentLength, target, targetPosition, segmentLength, CompareOptions.IgnoreCase) !=0) {
                            return false;
                        }
                        // Advance the input string
                        thisPosition = thisPosition + segmentLength + 1;
                    }
                    // Advance our target string
                    targetPosition = wsIndex + 1;


                    // Skip past multiple whitespace
                    while (thisPosition < Value.Length && Char.IsWhiteSpace(Value[thisPosition])) {
                        thisPosition++;
                        matchLength++;
                    }
                } while ((wsIndex = target.IndexOfAny(WhiteSpaceChecks, targetPosition)) >= 0);
                // now check the last segment;
                if (targetPosition < target.Length) {
                    int segmentLength = target.Length - targetPosition;
                    if (thisPosition > Value.Length - segmentLength) {
                        return false;
                    }
                    if (m_info.Compare(Value, thisPosition, segmentLength, target, targetPosition, segmentLength, CompareOptions.IgnoreCase) !=0) {
                        return false;
                    }
                }
            }

            if (checkWordBoundary) {
                int nextCharIndex = Index + matchLength;
                if (nextCharIndex < Value.Length) {
                    if (Char.IsLetter(Value[nextCharIndex])) {
                        return (false);
                    }
                }
            }
            return (true);
        }
开发者ID:stormleoxia,项目名称:referencesource,代码行数:64,代码来源:datetimeparse.cs

示例2: IsValidDirectoryName

    internal static bool IsValidDirectoryName(String name) {
        if (String.IsNullOrEmpty(name)) {
            return false;
        }

        if (name.IndexOfAny(_invalidFileNameChars, 0) != -1) {
            return false;
        }

        if (name.Equals(".") || name.Equals("..")) {
            return false;
        }

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

示例3: QuoteString

	// Quote a string and write it to a builder.
	private static void QuoteString(StringBuilder builder, String value)
			{
				int posn;
				char ch;

				// If the value contains token characters, then don't quote.
				for(posn = 0; posn < value.Length; ++posn)
				{
					ch = value[posn];
					if(ch < 0x20 || ch >= 0x7F)
					{
						break;
					}
				}
				if(posn >= value.Length && value.IndexOfAny(specials) == -1)
				{
					builder.Append(value);
					return;
				}

				// Quote the string.
				builder.Append('"');
				for(posn = 0; posn < value.Length; ++posn)
				{
					ch = value[posn];
					if(ch == '"')
					{
						builder.Append('\\');
						builder.Append('"');
					}
					else if(ch == '\\')
					{
						builder.Append('\\');
						builder.Append('\\');
					}
					else
					{
						builder.Append(ch);
					}
				}
				builder.Append('"');
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:43,代码来源:Cookie.cs

示例4: WriteTextEncodedAttribute

        /// <devdoc>
        /// <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal void WriteTextEncodedAttribute(String attribute, String value) {
            // Unlike HTML encoding, we need to replace $ with $$, and <> with &lt; and &gt;.
            // We can't do this by piggybacking HtmlTextWriter.WriteAttribute, because it
            // would translate the & in &lt; or &gt; to &amp;. So we more or less copy the
            // ASP.NET code that does similar encoding.
            Write(' ');
            Write(attribute);
            Write("=\"");
            int cb = value.Length;
            int pos = value.IndexOfAny(_attributeCharacters);
            if (pos == -1) {
                Write(value);
            }
            else {
                char[] s = value.ToCharArray();
                int startPos = 0;
                while (pos < cb) {
                    if (pos > startPos) {
                        Write(s, startPos, pos - startPos);
                    }

                    char ch = s[pos];
                    switch (ch) {
                    case '\"':
                        Write("&quot;");
                        break;
                    case '&':
                        Write("&amp;");
                        break;
                    case '<':
                        Write("&lt;");
                        break;
                    case '>':
                        Write("&gt;");
                        break;
                    case '$':
                        Write("$$");
                        break;
                    }

                    startPos = pos + 1;
                    pos = value.IndexOfAny(_attributeCharacters, startPos);
                    if (pos == -1) {
                        Write(s, startPos, cb - startPos);
                        break;
                    }
                }
            }
            Write('\"');
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:53,代码来源:WmlTextWriter.cs

示例5: EncodeTab

    //
    // Implemenation of IManagedContext
    //

    // As we use tab as separator, marshaling data will be corrupted
    // when user inputs contain any tabs. Therefore, we have tabs in user
    // inputs encoded before marshaling (Dev10 #692392)
    private static String EncodeTab(String value) {
        if (String.IsNullOrEmpty(value) || value.IndexOfAny(TabOrBackSpace) < 0) {
            return value;
        }
        return value.Replace("\b", "\bB").Replace("\t", "\bT");
    }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:13,代码来源:AspCompat.cs

示例6: MeasureString

	public SizeF MeasureString(String text, Font font, SizeF layoutArea,
	                           StringFormat format, out int charactersFitted,
	                           out int linesFilled)
			{
				// bail out now if there's nothing to measure
				if(((Object)text) == null || text.Length == 0)
				{
					charactersFitted = 0;
					linesFilled = 0;
					return new SizeF(0.0f, 0.0f);
				}

				// ensure we have a string format
				if(format == null)
				{
					format = new StringFormat();
				}

				// select the font
				SelectFont(font);

				// measure the string
				Size size = ToolkitGraphics.MeasureString
					(text, null, null, out charactersFitted,
					 out linesFilled, false);

				// determine if the string contains a new line
				bool containsNL =
					(text.IndexOfAny(new char[] { '\r', '\n' }) >= 0);

				// get the layout width
				float width = layoutArea.Width;

				// return the size information based on wrapping behavior
				if((format.FormatFlags & StringFormatFlags.NoWrap) == 0 &&
				   ((size.Width >= width && width != 0.0f) || containsNL))
				{
					// create the layout rectangle
					Rectangle layout = new Rectangle
						(0, 0, (int)width, (int)layoutArea.Height);

					// declare the drawing position calculator
					StringDrawPositionCalculator calculator;

					// create the drawing position calculator
					calculator = new StringDrawPositionCalculator
						(text, this, font, layout , format);

					// calculate the layout of the text
					calculator.LayoutByWords();

					// calculate and return the bounds of the text
					SizeF s = calculator.GetBounds
						(out charactersFitted, out linesFilled);
					s.Width += font.SizeInPoints*DpiX/184.8592F;
					return s;
				}
				else
				{
					// NOTE: we use the font height here, rather than
					//       the height returned by the toolkit, since
					//       the toolkit returns the actual height of
					//       the text but the expected behavior is that
					//       the height be the font height and the width
					//       is all that is actually measured

					// set the number of characters fitted
					charactersFitted = text.Length;

					// set the number of lines filled
					linesFilled = 1;

					// return the size of the text
					return new SizeF(size.Width + font.SizeInPoints*DpiX/184.8592f, font.Height);
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:76,代码来源:Graphics.cs


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