Results 1 to 2 of 2

Thread: string manipulation

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Belgium
    Posts
    8
    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



  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width