Click here to Skip to main content
15,892,072 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionstring trim Pin
tanarnelinistit24-Jul-06 1:44
tanarnelinistit24-Jul-06 1:44 
AnswerRe: string trim Pin
_AnsHUMAN_ 24-Jul-06 2:00
_AnsHUMAN_ 24-Jul-06 2:00 
AnswerRe: string trim Pin
James R. Twine24-Jul-06 3:03
James R. Twine24-Jul-06 3:03 
GeneralRe: string trim Pin
Blake Miller24-Jul-06 12:13
Blake Miller24-Jul-06 12:13 
GeneralRe: string trim Pin
James R. Twine24-Jul-06 14:09
James R. Twine24-Jul-06 14:09 
AnswerRe: string trim Pin
David Crow24-Jul-06 4:14
David Crow24-Jul-06 4:14 
AnswerRe: string trim Pin
Zac Howland24-Jul-06 6:29
Zac Howland24-Jul-06 6:29 
AnswerRe: string trim Pin
James R. Twine24-Jul-06 8:10
James R. Twine24-Jul-06 8:10 
   OK - perhaps a simple example of trimming a string in-place, because you did not mention the word "copy" in your post (this code comes slightly modified from my TStaticString class):
void    TrimRight( LPTSTR cpString, 
                LPCTSTR cpTrimWhat = _T( " " ) )        // Trim Trailing Characters From String
{
    size_t  stStrLen = ::_tcslen( cpString );           // Get String Length
 
    if( !stStrLen )                                     // If No String Length
    {
        return;                                         // Stop Here
    }
    LPTSTR  cpCursor = ( cpString + ( stStrLen - 1 ) ); // Start At End Of String (Not The NUL Terminator)
    size_t  stCount = 0;
 
    while( ( stCount < stStrLen) &&                     // While String Characters Available
            ( ::_tcschr( cpTrimWhat, *cpCursor ) ) )    // Look For Target To Remove
    {
        ++stCount;                                      // Increment Count While Found
        --cpCursor;                                     // Decrement Cursor Location
    }
    if( stCount )                                       // If Trimming Characters Found
    {
        ++cpCursor;                                     // Advance Cursor Back To Last Trailing Character
        *cpCursor = _T( '\0' );                         // Terminate The String Right There
    }
    return;                                             // Done!
}
   See how that works for you.  Specify the characters to   Example of use:
TCHAR   caTest[ 32 ];

strcpy( caTest, _T( "abc\t   " ) );
TrimRight( caTest );
strcpy( caTest, _T( "abc\t   " ) );
TrimRight( caTest, "\t " );
   The first call will trim up to the tab character, the second will also trim the tab character.

   Peace!

-=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites
(Please rate this post!)

QuestionDatabase connection in vc++ Pin
ningthemcha24-Jul-06 1:04
ningthemcha24-Jul-06 1:04 
AnswerRe: Database connection in vc++ Pin
_AnsHUMAN_ 24-Jul-06 1:19
_AnsHUMAN_ 24-Jul-06 1:19 
AnswerRe: Database connection in vc++ Pin
David Crow24-Jul-06 2:59
David Crow24-Jul-06 2:59 
QuestionDisplaying the content of control to new form contron Pin
ningthemcha24-Jul-06 1:02
ningthemcha24-Jul-06 1:02 
AnswerRe: Displaying the content of control to new form contron Pin
_AnsHUMAN_ 24-Jul-06 2:33
_AnsHUMAN_ 24-Jul-06 2:33 
AnswerRe: Displaying the content of control to new form contron Pin
Hamid_RT24-Jul-06 2:41
Hamid_RT24-Jul-06 2:41 
QuestionRe: Displaying the content of control to new form contron Pin
David Crow24-Jul-06 3:03
David Crow24-Jul-06 3:03 
Questionasynchronized I/O == multiplexing I/O? Pin
George_George24-Jul-06 0:57
George_George24-Jul-06 0:57 
AnswerRe: asynchronized I/O == multiplexing I/O? Pin
peterchen24-Jul-06 2:12
peterchen24-Jul-06 2:12 
GeneralRe: asynchronized I/O == multiplexing I/O? [modified] Pin
George_George25-Jul-06 2:06
George_George25-Jul-06 2:06 
QuestionSet Focus to Button? Pin
bosfan24-Jul-06 0:37
bosfan24-Jul-06 0:37 
AnswerRe: Set Focus to Button? Pin
toxcct24-Jul-06 0:41
toxcct24-Jul-06 0:41 
GeneralRe: Set Focus to Button? Pin
bosfan24-Jul-06 1:09
bosfan24-Jul-06 1:09 
AnswerRe: Set Focus to Button? Pin
_AnsHUMAN_ 24-Jul-06 0:42
_AnsHUMAN_ 24-Jul-06 0:42 
GeneralRe: Set Focus to Button? Pin
bosfan24-Jul-06 1:26
bosfan24-Jul-06 1:26 
QuestionReading text from where mouse is double clicked!!! Pin
_AnsHUMAN_ 24-Jul-06 0:20
_AnsHUMAN_ 24-Jul-06 0:20 
AnswerRe: Reading text from where mouse is double clicked!!! Pin
Programm3r24-Jul-06 0:31
Programm3r24-Jul-06 0:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.