|
-
Nov 7th, 2001, 04:22 PM
#1
Thread Starter
Frenzied Member
String Manipulation
Okay now I have my text from a file. Is there an easy way to search the string other than making some huge function?
-
Nov 7th, 2001, 05:01 PM
#2
in C
strchr(bigstring, character) looks for a char in a string
str(bigstring, littlestring) looks for a small string in a big one
C++
CString has instr to find substrings.
-
Nov 7th, 2001, 06:25 PM
#3
Thread Starter
Frenzied Member
what header is needed?
error C2065: 'str' : undeclared identifier
-
Nov 7th, 2001, 06:26 PM
#4
Monday Morning Lunatic
CString is MFC, Jim For normal C++ it's best to use string.
However, if it's a large file (more than about 250K), it can be a lot faster to use a rope.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 7th, 2001, 06:53 PM
#5
oops -
strstr(bigstring, littlestring);
my typo.
If you go into VC++ help and look up strcmp( ) or any other string thing - you have a link to all of the functions as well as CString.
Parskie is right - but th eonly serious code I've written in C++ was MFC - a while back. I'm back to C at work now.
-
Nov 8th, 2001, 09:44 AM
#6
parksie: what is a rope? I never heard of it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 8th, 2001, 10:01 AM
#7
transcendental analytic
I haven't used the STL::rope yet but it's suppose be a string that is good for frequent concentrations of long strings, in contrast to char arrays which would take linear time to concentrate.
http://www.sgi.com/tech/stl/Rope.html
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 9th, 2001, 05:31 PM
#8
Thread Starter
Frenzied Member
-
Nov 9th, 2001, 06:15 PM
#9
Code:
#include <stdio.h>
void main(void){
char *buf, *s;
int where;
char bigstring[100];
char littlestring[10];
memset(littlestring,'\0',sizeof(littlestring) );/* zero out memory */
memset(bigstring,'\0',sizeof(bigstring) );
strcpy(bigstring,"this is a test."); /* put stuff in test strings */
strcpy(littlestring,"is");
buf = (char*) strstr(bigstring,littlestring); /* do instr( ) */
if (buf != NULL) {/* we found one if buf != NULL */
s = bigstring;
where = buf - s;
printf("position = %d\n",where);
}
else {
printf("Not found. \n");
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|