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


C# StringBuilder.IndexOf方法代码示例

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


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

示例1: StringBuilderIndexOf

        public void StringBuilderIndexOf() {
            // name of the song that I was listening when I create the function :)
            var sb = new StringBuilder("Blue Pilots Project - Million Clouds");

            Assert.AreEqual(5, sb.IndexOf("Pilots"));
            Assert.AreEqual(20, sb.IndexOf('-'));
            Assert.AreEqual(22, sb.IndexOf("m", 0, true));
        }
开发者ID:lovethisgame,项目名称:SharpNL,代码行数:8,代码来源:StringBuilderExtensionTest.cs

示例2: GetStartIndex

 private static int GetStartIndex(StringBuilder value)
 {
    int startIndex = value.IndexOf("\r\n\"", false);
    if (startIndex >= 0)
    {
       startIndex += 3;
    }
    else
    {
       startIndex = value.IndexOf("\n\"", false);
       if (startIndex >= 0)
       {
          startIndex += 2;
       }
       else
       {
          startIndex = 0;
       }
    }
    return startIndex;
 }
开发者ID:harlam357,项目名称:hfm-net,代码行数:21,代码来源:LogFragment.cs

示例3: Main

        static void Main(string[] args)
        {
            // расширение для StringBuilder (public, static not implement, first argument is this)
            string str = "hello World for test!";
            StringBuilder sb = new StringBuilder(str);
            Int32 index = sb.IndexOf('W');
            Console.WriteLine("sb.IndexOf('W') = "+ index);

            // расширение для IEnumerable (public, static not implement, first argument is this)
            List<string> list = new List<string>() { "1", "2", "3", "4", "5" };
            list.ShowItems();

            "hello my little pony".ShowItems();

            //list.Count();
            Console.ReadLine();
        }
开发者ID:ElianaArt,项目名称:2015,代码行数:17,代码来源:Program.cs

示例4: LetNode

        public LetNode(Token<TokenType> t)
        {
            //Note:Syntax: let <var> = <expr>
            StringBuilder statement = new StringBuilder(t.TokenValue);
            statement.RemoveSpaceAtBegin();
            statement.RemoveKeywordAtBegin(TemplateKeywords.Let);
            statement.RemoveSpaceAtBegin();

            //this._varName = statement.ExtractFirstToken();
            int idx = statement.IndexOf('=');
            if (idx < 0)
                ExceptionHelper.ThrowKeywordExpected("=");
            this._varName = statement.ToString().Substring(0, idx).Trim();
            statement.RemoveBegin(_varName);

            if (!_varName.IsValidVariableName())
                ExceptionHelper.ThrowInvalidVarName(_varName);

            statement.RemoveSpaceAtBegin();
            statement.RemoveKeywordAtBegin("=");
            this._expression = statement.ToString().Trim();
            if (_expression.Length == 0)
                ExceptionHelper.ThrowSyntaxError(t.TokenValue);
        }
开发者ID:rexzh,项目名称:RexToy,代码行数:24,代码来源:LetNode.cs

示例5: GetWordAfter

        public static string GetWordAfter(string stringToStartAfter, StringBuilder entireString, int indexToStartAt, StringComparison comparison)
        {
            int indexOf = entireString.IndexOf(stringToStartAfter, indexToStartAt, true);
            if (indexOf != -1)
            {
                int startOfWord = indexOf + stringToStartAfter.Length;

                // Let's not count the start of the word if it's a newline
                while (entireString[startOfWord] == WhitespaceChars[0] ||
                    entireString[startOfWord] == WhitespaceChars[1] ||
                    entireString[startOfWord] == WhitespaceChars[2] ||
                    entireString[startOfWord] == WhitespaceChars[3])
                {
                    startOfWord++;
                }

                int endOfWord = entireString.IndexOfAny(WhitespaceChars, startOfWord);
                if (endOfWord == -1)
                {
                    endOfWord = entireString.Length;
                }

                return entireString.Substring(startOfWord, endOfWord - startOfWord);
            }
            else
            {
                return null;
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:29,代码来源:StringFunctions.cs

示例6: FindStartIndex

 private static int FindStartIndex(StringBuilder buffer, int messageIndex)
 {
     int index = buffer.IndexOf(CarriageReturnLineFeed, messageIndex, false);
      return index >= 0 ? index : buffer.IndexOf(LineFeed, messageIndex, false);
 }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:5,代码来源:MessageCache.cs

示例7: FindEndIndex

        private static int FindEndIndex(StringBuilder buffer, int startIndex)
        {
            int index = buffer.IndexOf(String.Concat(CarriageReturnLineFeed, PyonFooter, CarriageReturnLineFeed), startIndex, false);
             if (index >= 0)
             {
            return index;
             }

             index = buffer.IndexOf(String.Concat(LineFeed, PyonFooter, LineFeed), startIndex, false);
             if (index >= 0)
             {
            return index;
             }

             //index = buffer.IndexOf(PyonFooter, startIndex, StringComparison.Ordinal);
             //if (index >= 0)
             //{
             //   return index;
             //}

             return -1;
        }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:22,代码来源:MessageCache.cs

示例8: GetNextJsonMessage

        /// <summary>
        /// Parse first message from the data buffer and remove it from the buffer value.  The remaining buffer value is returned to the caller.
        /// </summary>
        /// <param name="buffer">Data buffer value.</param>
        /// <returns>JsonMessage or null if no message is available in the buffer.</returns>
        internal static JsonMessage GetNextJsonMessage(StringBuilder buffer)
        {
            if (buffer == null) return null;

             // find the header
             int messageIndex = buffer.IndexOf(PyonHeader, false);
             if (messageIndex < 0)
             {
            return null;
             }
             // set starting message index
             messageIndex += PyonHeader.Length;

             // find the first CrLf or Lf character after the header
             int startIndex = FindStartIndex(buffer, messageIndex);
             if (startIndex < 0) return null;

             // find the footer
             int endIndex = FindEndIndex(buffer, startIndex);
             if (endIndex < 0)
             {
            return null;
             }

             // create the message and set received time stamp
             var message = new JsonMessage { Received = DateTime.UtcNow };
             // get the message name
             message.Key = buffer.Substring(messageIndex, startIndex - messageIndex);

             // get the PyON message
             buffer.SubstringBuilder(startIndex, message.Value, endIndex - startIndex);
             // replace PyON values with JSON values
             message.Value.Replace(": None", ": null");

             // set the index so we know where to trim the string (end plus footer length)
             int nextStartIndex = endIndex + PyonFooter.Length;
             // if more buffer is available set it and return, otherwise set the buffer empty
             if (nextStartIndex < buffer.Length)
             {
            buffer.Remove(0, nextStartIndex);
             }
             else
             {
            buffer.Clear();
             }

             return message;
        }
开发者ID:kszysiu,项目名称:hfm-net,代码行数:53,代码来源:MessageCache.cs

示例9: ClearContent

        public void ClearContent(StringBuilder content)
        {
            content.Replace('\r', ' ');
            content.Replace('\n', ' ');
            content.Replace('\0', ' ');
            content.Replace('\t', ' ');



            while (content.IndexOf("  ") >= 0)
                content.Replace("  ", " ");

            while (content.IndexOf("href =") >= 0)
                content.Replace("href =", "href=");

            while (content.IndexOf("\"") >= 0)
                content.Replace("\"", "");

            while (content.IndexOf("'") >= 0)
                content.Replace("'", "");

            while (content.IndexOf("&amp;") >= 0)
                content.Replace("&amp;", "&");

        }
开发者ID:MaxIakovliev,项目名称:asp.net-mvc-real-estate,代码行数:25,代码来源:HtmlParser.cs

示例10: IsWorkflow

        bool IsWorkflow(StringBuilder serviceData)
        {

            var startIdx = serviceData.IndexOf("<XamlDefinition>", 0, false);
            if(startIdx >= 0)
            {
                var endIdx = serviceData.IndexOf("</XamlDefinition>", startIdx, false);
                var dif = endIdx - startIdx;

                // we know a blank wf is larger then our max string size ;)
                return startIdx > 0 && dif > (GlobalConstants.MAX_SIZE_FOR_STRING - 1024);
            }

            return false;
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:15,代码来源:ServiceDefinitionLoader.cs

示例11: TS_TestControlProperties

        /// -------------------------------------------------------------------------
        /// <summary>
        /// Common code that is called from the Control tests to verify the properties associated with a control
        /// </summary>
        /// -------------------------------------------------------------------------
        internal void TS_TestControlProperties()
        {
            string[] frameworks = new string[] { m_le.Current.FrameworkId, DEFAULT_FRAMEWORK };

            ControlType ctType = m_le.Current.ControlType;
            XmlNode node;

            // Things such as GetBoundingRect, GetClickablePoint return diffent values if they are on or off the viewable portion, 
            // so bail out with an invalid configuration
            if (m_le.Current.IsOffscreen == true)
            {
                // If we can scroll into view, try it
                if ((bool)m_le.GetCurrentPropertyValue(AutomationElement.IsScrollItemPatternAvailableProperty))
                {
                    ScrollItemPattern sip = m_le.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern;
                    try
                    {
                        Comment("Scrolling element({0}) into view", Library.GetUISpyLook(m_le));
                        sip.ScrollIntoView();
                    }
                    catch (InvalidOperationException)
                    {
                        ThrowMe(CheckType.IncorrectElementConfiguration, "Cannot test properties for elements that are not visible");
                    }
                }
                if (m_le.Current.IsOffscreen == true)
                    ThrowMe(CheckType.IncorrectElementConfiguration, "Cannot test properties for elements that are not visible");
                Comment("Element(" + Library.GetUISpyLook(m_le) + ") is now visible for testing");
            }

            // There is a better way of doing this, by quering the XML for specifics, but need to get this written
            ArrayList seenProps = new ArrayList();

            foreach (string frameWorkId in frameworks)
            {
                foreach (XmlNode n in GetNodes(XMLPROPERTIES, ctType, frameWorkId))
                {
                    node = n;
                    node = node.NextSibling;

                    if (node == null)
                        return;



                    // Go through all the XML nodes for the properties that this control supports.
                    // This will only test the properties that it finds in the XML.
                    while (node != null)
                    {
                        string property = new StringBuilder(node.Name).Replace("_", ".").ToString();
                        AutomationProperty ap = Helpers.GetPropertyByName(property);
                        if (seenProps.IndexOf(ap.ProgrammaticName) == -1)
                        {
                            seenProps.Add(ap.ProgrammaticName);

                            string patternName = property.Substring(0, property.IndexOf("."));

                            if ((patternName == "AutomationElement") || (PatternSupported(patternName)))
                            {

                                object currentValue = m_le.GetCurrentPropertyValue(ap);

                                Comment("Validating {0}.GetCurrentPropertyValue({1})={2}", ctType.ProgrammaticName, property, currentValue);
                                Comment("Node validation is {0}", node.InnerText.ToUpper(CultureInfo.CurrentCulture));

                                switch (node.InnerText.ToUpper(CultureInfo.CurrentCulture))
                                {
                                    case XML_NON_EMPTY_STRING:
                                        {
                                            if (currentValue is string)
                                            {
                                                string obj = (string)currentValue;
                                                if (String.IsNullOrEmpty(obj))
                                                {
                                                    ThrowMe(CheckType.Verification, "{0} : IsNullOrEmpty() returned true but should have been a valid string", property);
                                                }
                                            }
                                            else
                                            {
                                                ThrowMe(CheckType.Verification, "{0} : did not return correct data type, but returned {1}", property, currentValue.GetType().ToString());
                                            }
                                            break;
                                        }
                                    case XML_FALSE:
                                        {
                                            if (currentValue is bool)
                                            {
                                                bool obj = (bool)currentValue;
                                                if (obj != false)
                                                {
                                                    ThrowMe(CheckType.Verification, "{0} : did not return a false, but returned {1}", property, obj);
                                                }
                                            }
                                            else
                                            {
//.........这里部分代码省略.........
开发者ID:jeffras,项目名称:uiverify,代码行数:101,代码来源:ControlObject.cs

示例12: StringBuilder

        /// <summary>
        /// Splits the given string on every instance of a separator character, as long as the separator is not quoted. Each split
        /// piece is then unquoted if requested.
        /// </summary>
        /// <remarks>
        /// 1) Unless requested to keep empty splits, a block of contiguous (unquoted) separators is treated as one separator.
        /// 2) If no separators are given, the string is split on whitespace.
        /// </remarks>
        /// <param name="input"></param>
        /// <param name="maxSplits"></param>
        /// <param name="keepEmptySplits"></param>
        /// <param name="unquote"></param>
        /// <param name="emptySplits">[out] a count of all pieces that were empty, and thus discarded, per remark (1) above</param>
        /// <param name="separator"></param>
        /// <returns>ArrayList of all the pieces the string was split into.</returns>
        internal static ArrayList SplitUnquoted
        (
            string input,
            int maxSplits,
            bool keepEmptySplits,
            bool unquote,
            out int emptySplits,
            params char[] separator
        )
        {
            ErrorUtilities.VerifyThrow(maxSplits >= 2, "There is no point calling this method for less than two splits.");

            string separators = new StringBuilder().Append(separator).ToString();

            ErrorUtilities.VerifyThrow(separators.IndexOf('"') == -1, "The double-quote character is not supported as a separator.");

            StringBuilder splitString = new StringBuilder();
            splitString.EnsureCapacity(input.Length);

            bool isQuoted = false;
            int precedingBackslashes = 0;
            int splits = 1;

            for (int i = 0; (i < input.Length) && (splits < maxSplits); i++)
            {
                switch (input[i])
                {
                    case '\0':
                        // Pretend null characters just aren't there.  Ignore them.
                        Debug.Assert(false, "Null character in parameter");
                        break;

                    case '\\':
                        splitString.Append('\\');
                        precedingBackslashes++;
                        break;

                    case '"':
                        splitString.Append('"');
                        if ((precedingBackslashes % 2) == 0)
                        {
                            if (isQuoted &&
                                (i < (input.Length - 1)) &&
                                (input[i + 1] == '"'))
                            {
                                splitString.Append('"');
                                i++;
                            }
                            isQuoted = !isQuoted;
                        }
                        precedingBackslashes = 0;
                        break;

                    default:
                        if (!isQuoted &&
                            (((separators.Length == 0) && char.IsWhiteSpace(input[i])) ||
                            (separators.IndexOf(input[i]) != -1)))
                        {
                            splitString.Append('\0');
                            if (++splits == maxSplits)
                            {
                                splitString.Append(input, i + 1, input.Length - (i + 1));
                            }
                        }
                        else
                        {
                            splitString.Append(input[i]);
                        }
                        precedingBackslashes = 0;
                        break;
                }
            }

            ArrayList pieces = new ArrayList();
            emptySplits = 0;

            foreach (string splitPiece in splitString.ToString().Split(s_splitMarker, maxSplits))
            {
                string piece = (unquote
                    ? Unquote(splitPiece)
                    : splitPiece);

                if ((piece.Length > 0) || keepEmptySplits)
                {
                    pieces.Add(piece);
//.........这里部分代码省略.........
开发者ID:cameron314,项目名称:msbuild,代码行数:101,代码来源:QuotingUtilities.cs

示例13: ParseStringValue

        private static string ParseStringValue(string property, IConfiguration config, ISet<string> visitedPlaceHolders, ILogger logger = null)
        {


            if (string.IsNullOrEmpty(property))
                return property;

            StringBuilder result = new StringBuilder(property);

            int startIndex = property.IndexOf(PREFIX);
            while (startIndex != -1)
            {
                int endIndex = FindEndIndex(result, startIndex);
                if (endIndex != -1)
                {
                    
                    string placeholder = result.Substring(startIndex + PREFIX.Length, endIndex);
                    string originalPlaceholder = placeholder;

                    if (!visitedPlaceHolders.Add(originalPlaceholder))
                    {
                        throw new ArgumentException(String.Format("Circular placeholder reference '{0}' in property definitions",
                            originalPlaceholder));
                    }
                    // Recursive invocation, parsing placeholders contained in the placeholder key.
                    placeholder = ParseStringValue(placeholder, config, visitedPlaceHolders);
                    // Handle array references foo:bar[1]:baz format -> foo:bar:1:baz
                    string lookup = placeholder.Replace('[', ':').Replace("]", "");
                    // Now obtain the value for the fully resolved key...
                    string propVal = config[lookup];
                    if (propVal == null)
                    {
                        int separatorIndex = placeholder.IndexOf(SEPARATOR);
                        if (separatorIndex != -1)
                        {
                            string actualPlaceholder = placeholder.Substring(0, separatorIndex);
                            string defaultValue = placeholder.Substring(separatorIndex + SEPARATOR.Length);
                            propVal = config[actualPlaceholder];
                            if (propVal == null)
                            {
                                propVal = defaultValue;
                            }
                        }
                    }
                    if (propVal != null)
                    {
                        // Recursive invocation, parsing placeholders contained in these
                        // previously resolved placeholder value.
                        propVal = ParseStringValue(propVal, config, visitedPlaceHolders);
                        result.Replace(startIndex, endIndex + SUFFIX.Length, propVal);
                        logger?.LogVerbose("Resolved placeholder '{0}'" + placeholder);
                        startIndex = result.IndexOf(PREFIX, startIndex + propVal.Length);
                    }
                    else 
                    {
                        // Proceed with unprocessed value.
                        startIndex = result.IndexOf(PREFIX, endIndex + PREFIX.Length);
                    }
                    visitedPlaceHolders.Remove(originalPlaceholder);
                }
                else {
                    startIndex = -1;
                }
            }

            return result.ToString();
        }
开发者ID:chrisumbel,项目名称:Configuration,代码行数:67,代码来源:PropertyPlaceHolderHelper.cs

示例14: ReadVectorsFromFile


//.........这里部分代码省略.........
                    {
                        int indexSeparatorPosition = -1;
                        string inputLine = input.ReadLine().Trim();

                        int index = 0;

                        float value = 0;


                        #region old code

                        /*
                        string[] parts =inputLine.Split(vecPartsSeparator,StringSplitOptions.RemoveEmptyEntries);

                        //label
                        labels.Add(float.Parse(parts[0],CultureInfo.InvariantCulture));

                        //other parts with index and value
                        int m = parts.Length - 1;

                        //list of index and value for one vector
                        List<KeyValuePair<int, double>> vec = new List<KeyValuePair<int, double>>(m);
                        
                       
                        //extract index and value
                        for (int j = 0; j < m; j++)
                        {

                            //string[] nodeParts = parts[j + 1].Split(idxValSeparator);
                            //index = int.Parse(nodeParts[0]);
                            //value = float.Parse(nodeParts[1], System.Globalization.CultureInfo.InvariantCulture);
                            
                            //it is more memory eficcient than above version with split
                            indexSeparatorPosition = parts[j + 1].IndexOf(idxValSeparator[0]);
                            index = int.Parse(parts[j+1].Substring(0,indexSeparatorPosition) );
                            value = float.Parse(parts[j+1].Substring(indexSeparatorPosition+1));

                            vec.Add(new KeyValuePair<int, double>(index, value));
                            // v[index] = value;

                        }
                        */
                        #endregion

                        //add one space to the end of line, needed for parsing
                        string oneLine = new StringBuilder(inputLine).Append(" ").ToString();

                        int partBegin = -1, partEnd = -1;

                        partBegin = oneLine.IndexOf(vecPartsSeparator[0]);
                        //from begining to first space is label
                        float dataLabel = float.Parse(oneLine.Substring(0, partBegin), CultureInfo.InvariantCulture);
                        labels.Add(dataLabel);

                        if (coutLabels.ContainsKey(dataLabel))
                            coutLabels[dataLabel]++;
                        else
                            coutLabels[dataLabel] = 1;

                        index = -1;

                        value = -1;
                        partEnd = oneLine.IndexOf(vecPartsSeparator[0], partBegin + 1);

                        while (partEnd > 0)
                        {
开发者ID:maotong,项目名称:KMLib,代码行数:67,代码来源:IOHelpers.cs

示例15: SubstituteParam

        private void SubstituteParam(StringBuilder source, CodeDataGeneratorParam p)
        {
            if (p.Value != null)
            {
                int beginInd = source.IndexOf(p.KeyBegin);
                if (beginInd != -1)
                {
                    int endInd = source.IndexOf(p.KeyEnd, beginInd);

                    int ind, length;
                    if (!p.SaveKey)
                    {
                        ind = beginInd;
                        length = endInd + p.KeyEnd.Length - ind;
                    }
                    else
                    {
                        ind = beginInd + p.KeyBegin.Length;
                        length = endInd - ind;
                    }
                    source = source.Remove(ind, length);

                    if (!IgnoreIndents)
                        source = InsertWithIndents(source, ind, p.Value);
                    else
                        source = source.Insert(ind, p.Value);
                }
            }
        }
开发者ID:KvanTTT,项目名称:Freaky-Sources,代码行数:29,代码来源:CodeDataGenerator.cs


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