Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Occurs in C#
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01566946
Message ID:
01566959
Views:
34
>>
>> /// <summary>
>>      /// Occurs function
>>      /// </summary>
>>      /// <param name="source"></param>
>>      /// <param name="pattern"></param>
>>      /// <returns></returns>
>>      public static Int32 Occurs(this String source, char pattern)
>>      {
>>         return source.Split(pattern).Length - 1;
>>      }
>>
>>      public static Int32 Occurs(this String source, String pattern)
>>      {
>>         return (source.Length - source.Replace(pattern, "").Length)/pattern.Length;
>>      }
From the link you provided this was supposed to be fasted for char matching:
int length = testchars.Length;
>for (int n = length-1; n >= 0; n--)
>{
>    if (testchars[n] == '/')
>        count++;
>}
Right, but I think the conclusion is that the speed difference is negligible unless running in a loop. I don't plan (for now) to run it in a loop.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform