Click here to Skip to main content
15,885,767 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to count a character in a string? Pin
Luc Pattyn8-Jun-09 4:50
sitebuilderLuc Pattyn8-Jun-09 4:50 
AnswerRe: How to count a character in a string? Pin
Manas Bhardwaj8-Jun-09 3:54
professionalManas Bhardwaj8-Jun-09 3:54 
GeneralRe: How to count a character in a string? Pin
SimpleData8-Jun-09 4:10
SimpleData8-Jun-09 4:10 
AnswerRe: How to count a character in a string? Pin
Skymir8-Jun-09 4:17
Skymir8-Jun-09 4:17 
GeneralRe: How to count a character in a string? Pin
Blue_Boy8-Jun-09 4:26
Blue_Boy8-Jun-09 4:26 
AnswerRe: How to count a character in a string? [modified] Pin
Luc Pattyn8-Jun-09 4:51
sitebuilderLuc Pattyn8-Jun-09 4:51 
GeneralRe: How to count a character in a string? Pin
harold aptroot8-Jun-09 5:52
harold aptroot8-Jun-09 5:52 
GeneralRe: How to count a character in a string? Pin
Luc Pattyn8-Jun-09 7:17
sitebuilderLuc Pattyn8-Jun-09 7:17 
Hi Harold,

I ran some tests (VS C# 2008, all release build), and the general conclusions are:
- optimum tactic depends on the data, mostly on the fraction of special characters (';') present;
- with lots of ';' the explicit loops are better;
- with few or no ';' string methods are better;
- my single-line approach based on string.Replace never wins;
- when string.Length is present in the for statement, it consumes >30% of the CPU cycles;
- with fewer than 15% of special chars, the winner is IndexOf (see below); for extemely long strings it is up to 4 times faster than the second fastest (explicit loop without Length in for statement).

int n=0;
int start=0;
for (; ; ) {
    int j=test.IndexOf(';', start);
    if (j<0) break;
    n++;
    start=j+1;
}


Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

GeneralRe: How to count a character in a string? Pin
harold aptroot8-Jun-09 7:45
harold aptroot8-Jun-09 7:45 
Questionzedgraph Pin
yankoon8-Jun-09 3:06
yankoon8-Jun-09 3:06 
QuestionDynamically adding checkboxes in datagridview. Pin
deepseeindeepsy8-Jun-09 3:02
deepseeindeepsy8-Jun-09 3:02 
AnswerRe: Dynamically adding checkboxes in datagridview. Pin
yankoon8-Jun-09 3:11
yankoon8-Jun-09 3:11 
GeneralRe: Dynamically adding checkboxes in datagridview. Pin
deepseeindeepsy8-Jun-09 19:11
deepseeindeepsy8-Jun-09 19:11 
QuestionEXCEPTIONN: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed Pin
Ashwanth Sreedharan8-Jun-09 1:34
Ashwanth Sreedharan8-Jun-09 1:34 
AnswerRe: EXCEPTIONN: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed Pin
Rob Philpott8-Jun-09 2:07
Rob Philpott8-Jun-09 2:07 
AnswerRe: EXCEPTIONN: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed Pin
Ashwanth Sreedharan8-Jun-09 2:12
Ashwanth Sreedharan8-Jun-09 2:12 
QuestionHow can I know when a user clicks on Back button on top left corner of IE window using c#? Pin
svt gdwl8-Jun-09 1:10
svt gdwl8-Jun-09 1:10 
AnswerRe: How can I know when a user clicks on Back button on top left corner of IE window using c#? Pin
musefan8-Jun-09 2:03
musefan8-Jun-09 2:03 
Questionuser control design time event Pin
Abdul Rahman Hamidy8-Jun-09 0:06
Abdul Rahman Hamidy8-Jun-09 0:06 
AnswerRe: user control design time event Pin
Simon P Stevens8-Jun-09 1:03
Simon P Stevens8-Jun-09 1:03 
GeneralRe: user control design time event Pin
Abdul Rahman Hamidy14-Jun-09 19:30
Abdul Rahman Hamidy14-Jun-09 19:30 
QuestionSet a value to MDM T02 TXA-2-3 using NHapi? Pin
jingzo7-Jun-09 23:36
jingzo7-Jun-09 23:36 
AnswerRe: Set a value to MDM T02 TXA-2-3 using NHapi? Pin
jingzo10-Jun-09 23:21
jingzo10-Jun-09 23:21 
GeneralRe: Set a value to MDM T02 TXA-2-3 using NHapi? Pin
Member 921850128-Dec-22 7:37
Member 921850128-Dec-22 7:37 
QuestionDatagridview programming problem Pin
PrakashPaul7-Jun-09 23:36
PrakashPaul7-Jun-09 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.