|
-
Oct 3rd, 2000, 11:42 AM
#1
Thread Starter
New Member
I need some help for string manipulation (without CString class).
I know basics of C++, but never used strings.
For example I need a function for appending a backslash after a directory
name:
VOID WINAPI AppendSlash(LPTSTR *lpFileName)
{
len = lstrlen(*lpFileName) + 1;
if (len > 0 && szBuffer[len] != '\\')
{
// Modify string by adding a backsslash
}
}
Thanks,
Jef Driesen
-
Oct 3rd, 2000, 02:24 PM
#2
Monday Morning Lunatic
How 'bout this:
Code:
void WINAPI AppendSlash(LPTSTR *lpFileName) {
long lLength = _tcslen(lpFileName);
if(len > 0 && lpFileName[lLength-1] != '\\') {
lpFileName[lLength] = '\\';
}
}
This is the safest way, as long as you pass a buffer that's at least a character longer, unless it already has a backslash.
This is to try and cut down on pointer-related problems (you pass a pointer which has been supplied to something else. the pointer is reassigned, and gets invalidated )
Although I would suggest the STL string class - it's fast and doesn't have allocation bugs (like CString)(although something like this in your code is suggested
Code:
#define String basic_string<TCHAR>
...then use String rather than string so that Unicode doesn't break your app.
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
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
|