Click here to Skip to main content
15,886,258 members
Articles / Programming Languages / C++
Article

XTrim - trim leading and trailing whitespace characters

Rate me:
Please Sign up or sign in to vote.
4.09/5 (8 votes)
20 May 2003CPOL 86.3K   919   13   12
XTrim implements _tcsltrim and _tcsrtrim - CRT-like functions to trim whitespace.

Introduction

XTrim implements _tcsltrim and _tcsrtrim, non-MFC functions to trim whitespace from a string.

Function Descriptions

  • _tcsltrim() - Remove leading whitespace.
    ///////////////////////////////////////////////////////////////////////////////
    //
    // _tcsltrim()
    //
    // Purpose:     Removes (trims) leading whitespace characters from a string
    //
    // Parameters:  pszSource - Pointer to the null-terminated string to be trimmed.
    //                          On return, pszSource will hold the trimmed string
    //
    // Returns:     TCHAR *   - pointer to trimmed string
    // 
  • _tcsrtrim() - Remove trailing whitespace.
    ///////////////////////////////////////////////////////////////////////////////
    //
    // _tcsrtrim()
    //
    // Purpose:     Removes (trims) trailing whitespace characters from a string
    //
    // Parameters:  pszSource - Pointer to the null-terminated string to be trimmed.
    //                          On return, pszSource will hold the trimmed string
    //
    // Returns:     TCHAR *   - pointer to trimmed string
    // 

How To Use

To integrate XTrim functions into your app, you first need to add following files to your project:

  • XTrim.cpp
  • XTrim.h

If you include XTrim in project that uses precompiled headers, you must change C/C++ Precompiled Headers settings to Not using precompiled headers for XTrim.cpp.

Next, include the header file XTrim.h in appropriate project files. Now you are ready to start using XTrim. Please see XTrimTest.cpp for examples.

Revision History

Version 1.0 - 2003 May 11

  • Initial public release

Usage

This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions

 
GeneralOverCombination... Pin
Nitager4-Jan-09 9:58
Nitager4-Jan-09 9:58 
GeneralBugs and slow performance Pin
Robert F20-Sep-04 9:15
sussRobert F20-Sep-04 9:15 
GeneralThe joke's on me. Pin
WREY17-Oct-03 21:04
WREY17-Oct-03 21:04 
GeneralTwo byte space characters Pin
TQN21-May-03 17:57
TQN21-May-03 17:57 
GeneralRe: Two byte space characters Pin
Hans Dietrich21-May-03 19:45
mentorHans Dietrich21-May-03 19:45 
GeneralRe: Two byte space characters Pin
EIEN27-May-03 19:13
EIEN27-May-03 19:13 
GeneralRe: Two byte space characters Pin
User 543536417-Aug-08 14:57
User 543536417-Aug-08 14:57 
GeneralRe: Two byte space characters Pin
EIEN17-Aug-08 16:48
EIEN17-Aug-08 16:48 
GeneralRe: Two byte space characters Pin
User 543536417-Aug-08 18:06
User 543536417-Aug-08 18:06 
GeneralRe: Two byte space characters Pin
User 543536417-Aug-08 18:59
User 543536417-Aug-08 18:59 
GeneralRe: Two byte space characters Pin
Hans Dietrich17-Aug-08 19:14
mentorHans Dietrich17-Aug-08 19:14 
GeneralRe: Two byte space characters Pin
User 543536417-Aug-08 19:58
User 543536417-Aug-08 19:58 

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.