Click here for information on how to use code snippets in VS.NET (2005+)
Literal: ID: strSourceStringType: System.StringToolTip: The source string to search for the number of indices of a substring.Default: "as as as as as"Literal: ID: strSearchStringType: System.StringToolTip: The search string to search for in the source string.Default: "as"
ID: strSourceStringType: System.StringToolTip: The source string to search for the number of indices of a substring.Default: "as as as as as"
ID: strSearchStringType: System.StringToolTip: The search string to search for in the source string.Default: "as"
// NOTE: This code snippet is designed for VS.NET 2005 or later. String strSourceString = $strSourceString$; String strSearchString = $strSearchString$; int intStartIndex = 0; int intNumIndices = 0; while (strSourceString.IndexOf(strSearchString, intStartIndex) > -1) { intNumIndices++; intStartIndex = strSourceString.IndexOf(strSearchString, intStartIndex) + strSearchString.Length; } // intNumIndices = 5
XML View:
Determining the Number of Indices of a Substring within a String substringindices Determining the Number of Indices of a Substring within a String C# .Net Fun - http://www.dotnetfun.com - Michael G. strSourceString System.String The source string to search for the number of indices of a substring. "as as as as as" strSearchString System.String The search string to search for in the source string. "as" -1) { intNumIndices++; intStartIndex = strSourceString.IndexOf(strSearchString, intStartIndex) + strSearchString.Length; } // intNumIndices = 5 ]>
-1) { intNumIndices++; intStartIndex = strSourceString.IndexOf(strSearchString, intStartIndex) + strSearchString.Length; } // intNumIndices = 5 ]>