-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathString.cpp
More file actions
62 lines (44 loc) · 1.38 KB
/
String.cpp
File metadata and controls
62 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// String.cpp
#include "String.h"
int FindTextInString( LPCTSTR lpszToSearch, LPCTSTR lpszToFind )
{
int nResult = -1;
LPTSTR lpszToSearchLower;
LPTSTR lpszToFindLower;
LPTSTR lpszFound;
DWORD dwToSearchLength;
DWORD dwToFindLength;
// Store string lengths
dwToSearchLength = lstrlen( lpszToSearch );
dwToFindLength = lstrlen( lpszToFind );
// Allocate string memory
lpszToSearchLower = new char[ dwToSearchLength + sizeof( char ) ];
lpszToFindLower = new char[ dwToFindLength + sizeof( char ) ];
// Copy strings
lstrcpy( lpszToSearchLower, lpszToSearch );
lstrcpy( lpszToFindLower, lpszToFind );
// Convert strings to lower case
CharLower( lpszToSearchLower );
CharLower( lpszToFindLower );
// Find text
lpszFound = strstr( lpszToSearchLower, lpszToFindLower );
// Ensure that text was found
if( lpszFound )
{
// Successfully found text
// Update return value
nResult = ( lpszFound - lpszToSearchLower );
} // End of successfully found text
return nResult;
} // End of function FindTextInString
int GetNextNonSpace( LPCTSTR lpszToSearch, int nOffset )
{
int nResult = nOffset;
// Find next non-space
while( ( lpszToSearch[ nOffset ] == ASCII_SPACE_CHARACTER ) || ( lpszToSearch[ nOffset ] == ASCII_TAB_CHARACTER ) )
{
// Update return value
nResult ++;
}; // End of loop to find next non-space
return nResult;
} // End of function GetNextNonSpace