Trim leading/trailing characters

Web Site  Methods

 
Str::TrimLeft
 
Str& TrimLeft (const STRCHAR* charset = NULL)

Removes characters from the left of the string. If charset is not specified (i.e. NULL is passed), all leading spaces, tabs, CR and newline characters will be removed. Otherwise, all characters at the left of the string that match a character from the passed parameter will be removed.

The method returns a reference to the object itself for convenience.

Example:

   const STRCHAR*   to_remove = _T(" \t/-"); // All spaces, tabs, dash and forward slash Str
   x (_T("\t--help")); printf("%s\n",
   (const STRCHAR*) x.TrimLeft(to_remove));     // Will print help

 

 
Str::TrimRight
 
Str& TrimRight (const STRCHAR* charset = NULL)

Operates exactly like TrimLeft, but removes characters at the end of the string.

 

 
Str::Trim
 
Str& Trim (const STRCHAR* charset = NULL)

Operates exactly like TrimLeft and TrimRight called in sequence, i.e. removes characters from both the beginning and end of the string.

 

See also: Trimming / case / miscellaneous, Remove