|
-
August 6th, 1999, 04:20 AM
#1
How do I find a specified string in a file programmatically
Hi,
I'd like to know, given a string how do i find it in a set of files.
For example I have to find a string "CServer" in a set of .cpp files.
How do I implement this in my application?
Thanks in advance
-
August 6th, 1999, 04:58 AM
#2
Re: How do I find a specified string in a file programmatically
you can open each file in your file spec using CStdioFile and scan it using CStdioFile's ReadString method.
Then scan each line using CString's Find method.
-
August 6th, 1999, 05:03 AM
#3
Re: How do I find a specified string in a file programmatically
try that:
with CFile.Read get your file in a CString-buffer and then go ahead as follows...
int Find( LPCTSTR lpszSub ) const;
Return Value
The zero-based index of the first character in this CString object that matches the requested substring or characters; –1 if the substring or character is not found.
Parameters
ch A single character to search for.
lpszSub A substring to search for.
Remarks
Searches this string for the first match of a substring. The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr).
Example
The following example demonstrates the use of CString::Find.
// example for CString::Find
CString s( "abcdef" );
ASSERT( s.Find( 'c' ) == 2 );
ASSERT( s.Find( "de" ) == 3 );
-
August 6th, 1999, 05:04 AM
#4
Re: How do I find a specified string in a file programmatically
No actually I was looking for a class like CFindFile. Is this the only method I can do it?
-
August 6th, 1999, 06:27 AM
#5
Re: How do I find a specified string in a file programmatically
there is CFileFind class in MFC (not CFindFile).
is this the only method, you ask?
There is never ever only ONE method in programming :-)
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
|