Click here to Skip to main content
16,011,757 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Number of characters of a string Pin
CPallini17-Dec-07 22:02
mveCPallini17-Dec-07 22:02 
GeneralRe: Number of characters of a string Pin
CodingLover17-Dec-07 22:35
CodingLover17-Dec-07 22:35 
GeneralRe: Number of characters of a string Pin
Maxwell Chen17-Dec-07 22:36
Maxwell Chen17-Dec-07 22:36 
GeneralRe: Number of characters of a string Pin
CodingLover17-Dec-07 23:01
CodingLover17-Dec-07 23:01 
JokeRe: Number of characters of a string Pin
CPallini17-Dec-07 23:12
mveCPallini17-Dec-07 23:12 
GeneralRe: Number of characters of a string Pin
CodingLover17-Dec-07 23:31
CodingLover17-Dec-07 23:31 
GeneralRe: Number of characters of a string Pin
cp987617-Dec-07 23:37
cp987617-Dec-07 23:37 
GeneralRe: Number of characters of a string Pin
CPallini18-Dec-07 0:04
mveCPallini18-Dec-07 0:04 
cp9876 wrote:
If it is not what you need and you have to test for multiple characters, it is much more efficient to do:

switch (c)
{
case '\n':
case '\r':
case '\t':
case ' ':
..
break;
...
}


As general rule, yes. Anyway compilers are enough smart nowadays,
at least whenever optimization is turned on, as in VS Release Build:

		if (myString[i] == '\n' || myString[i] == '\r' || myString[i] == '\t')
00401040  movzx       ecx,word ptr string L"hello world" (4020F4h)[edx*2] 
00401048  cmp         cx,0Ah 
0040104C  je          test003+4Ah (40105Ah) 
0040104E  cmp         cx,0Dh 
00401052  je          test003+4Ah (40105Ah) 
00401054  cmp         cx,9 
00401058  jne         test003+4Dh (40105Dh) 
		{
			count++;
0040105A  add         esi,1 
		}
		switch(myString[i])
0040105D  movzx       ecx,cx 
00401060  cmp         ecx,9 
00401063  jl          test003+62h (401072h) 
00401065  cmp         ecx,0Ah 
00401068  jle         test003+5Fh (40106Fh) 
0040106A  cmp         ecx,0Dh 
0040106D  jne         test003+62h (401072h) 
		{
		case '\n':
		case '\r':
		case '\t':
			count++;
0040106F  add         esi,1 


Smile | :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.


GeneralRe: Number of characters of a string Pin
cp987618-Dec-07 0:15
cp987618-Dec-07 0:15 
GeneralRe: Number of characters of a string Pin
CPallini18-Dec-07 0:43
mveCPallini18-Dec-07 0:43 
GeneralRe: Number of characters of a string Pin
cp987618-Dec-07 10:07
cp987618-Dec-07 10:07 
GeneralYou're right Pin
CPallini18-Dec-07 12:33
mveCPallini18-Dec-07 12:33 
GeneralRe: Number of characters of a string Pin
CodingLover18-Dec-07 0:18
CodingLover18-Dec-07 0:18 
GeneralRe: Number of characters of a string Pin
Maxwell Chen18-Dec-07 1:16
Maxwell Chen18-Dec-07 1:16 
QuestionRe: Number of characters of a string Pin
David Crow18-Dec-07 3:20
David Crow18-Dec-07 3:20 
GeneralRe: Number of characters of a string Pin
David Crow18-Dec-07 3:30
David Crow18-Dec-07 3:30 
GeneralRe: Number of characters of a string Pin
jhwurmbach18-Dec-07 4:05
jhwurmbach18-Dec-07 4:05 
GeneralRe: Number of characters of a string Pin
David Crow18-Dec-07 4:14
David Crow18-Dec-07 4:14 
GeneralRe: Number of characters of a string Pin
jhwurmbach18-Dec-07 4:29
jhwurmbach18-Dec-07 4:29 
QuestionHow to read only the integer value of a txt file in C++ Pin
Cabomba17-Dec-07 20:20
Cabomba17-Dec-07 20:20 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Peter Weyzen17-Dec-07 20:48
Peter Weyzen17-Dec-07 20:48 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Cabomba17-Dec-07 21:36
Cabomba17-Dec-07 21:36 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Iain Clarke, Warrior Programmer17-Dec-07 23:48
Iain Clarke, Warrior Programmer17-Dec-07 23:48 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Cabomba18-Dec-07 19:50
Cabomba18-Dec-07 19:50 
GeneralRe: How to read only the integer value of a txt file in C++ Pin
Iain Clarke, Warrior Programmer18-Dec-07 23:56
Iain Clarke, Warrior Programmer18-Dec-07 23:56 

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.