xstring Class Reference

BASE CLASS FOR STRINGS. More...

#include <Zclassut.h>

List of all members.

Public Member Functions

int Locate (LPCTSTR lpsz_to_locate, unsigned long start_at_byte=0, bool ignore_case=__nocasesensitive)
int LocateLast (LPCTSTR lpsz_to_locate, unsigned long start_at_byte=0, bool casecheck=__nocasesensitive)
xstringErase (int at_char, unsigned long how_many_bytes)
xstringInsert (int at_char, LPCTSTR source_string, bool append=true)
xstringReplace (LPCTSTR lpsz_to_find, LPCTSTR lpsz_to_replace, bool replace_all=true, bool casecheck=__nocasesensitive)
bool isNotNull (void)
bool isNull (void)
bool isNotZero (void)
bool isZero (void)
xstring Middle (int at_char, int how_many_chars=-1)
xstring Left (int how_many_chars)
xstring Right (int how_many_chars)
xstring LeftZeroPad (int how_many_zeroes)
xstring LeftSpacePad (int how_many_spaces)
xstring RightSpacePad (int how_many_spaces)
xstring SpaceTrim (void)
xstring LeftSpaceTrim (void)
xstring RightSpaceTrim (void)
xstring LeftZeroTrim (void)
int Length (void)
xstringMask (unsigned char mask_char)
void Spaces (int how_many_spaces)
void startTokenize (void)
xstring nextToken (void)
xstring currentToken (void)
int indexToken (void)
xstringAppendNulls (short how_many_nulls=1)
xstringtoLowerCase (void)
xstringtoUpperCase (void)
xstring asLowerCase (void)
xstring asUpperCase (void)
 operator double (void)
 operator int (void)
 operator long (void)
 operator unsigned int (void)
 operator short (void)
 operator __int64 (void)
 operator unsigned short (void)
 operator char (void)
 operator unsigned char (void)

Detailed Description

BASE CLASS FOR STRINGS.

Provides methods for manipulating strings. xstring object consists of a variable-length sequence of characters and provides functions and operators using a syntax similar to that of Basic. Concatenation and comparison operators,together with simplified memory management,make xstring objects easier to use than ordinary character arrays.

xstring str="this is a string";
str+=" now it is longer";
str+=" without realloc and strcat!";

Member Function Documentation

xstring& xstring::AppendNulls ( short  how_many_nulls = 1  ) 

Appends null characters.

        xstring s="Hello world!";
        s.AppendNulls(-3);//underflow! No append occurs.
        s.AppendNulls(3);//modifies to "Hello world!\0\0\0\0"(content memory)
xstring xstring::asLowerCase ( void   )  [inline]
Returns:
the string value converted to lowercase.
        xstring a,s="Hello world!";
        a=s.asLowerCase();//returns "hello world!"
xstring xstring::asUpperCase ( void   )  [inline]
Returns:
the string value converted to uppercase.
        xstring s="Hello world!";
        s.asUpperCase();//returns "HELLO WORLD!"
xstring xstring::currentToken ( void   )  [inline]
Returns:
the current token(refer to startTokenize)
xstring& xstring::Erase ( int  at_char,
unsigned long  how_many_bytes 
)

Erases characters beginning at the specified position; overflow/underflow checking is performed. The position is 0 based.

        xstring s="Hello world!";
        s.Erase(2,3);//modifies to "He world!"
        s.Erase(-1,3);//underflow! No erase occurs
        s.Erase(0,300);//overflow! No erase occurs
int xstring::indexToken ( void   )  [inline]
Returns:
the current token character index(refer to startTokenize)
xstring& xstring::Insert ( int  at_char,
LPCTSTR  source_string,
bool  append = true 
)

Inserts a string before the specified position; overflow/underflow checking is performed. The position is 0 based.

        xstring s="Hello world!";
        s.Insert(6,"nice ");//modifies to "Hello nice world!"
        s.Insert(-20,"nice ");//underflow! No insert occurs
        s.Insert(6,"nice ",false);//modifies to "Hello nice "
        s.Insert(60,"nice ");//overflow! No insert occurs
bool xstring::isNotNull ( void   )  [inline]
Returns:
true if the object is not null.
bool xstring::isNotZero ( void   )  [inline]
Returns:
true if the object is not zero.
bool xstring::isNull ( void   ) 
Returns:
true if the object is null.
bool xstring::isZero ( void   )  [inline]
Returns:
true if the object is zero.
xstring xstring::Left ( int  how_many_chars  )  [inline]
Returns:
a specified number of characters from the left side
        xstring a,s="Hello world!";
        a=s.Left(2);//returns "He"
        a=s.Left(-2);//returns "Hello world!"
        a=s.Left(22);//returns "Hello world!"
xstring xstring::LeftSpacePad ( int  how_many_spaces  )  [inline]
Returns:
the string value padded with a specified number of spaces on left.
        xstring a,s="Hello world!";
        a=s.LeftSpacePad(18);//returns "      Hello world!"
        a=s.LeftSpacePad(13);//returns " Hello world!"
        a=s.LeftSpacePad(-1);//returns "Hello world!"
        a=s.LeftSpacePad(8);//returns "Hello wo"
xstring xstring::LeftSpaceTrim ( void   )  [inline]

Removes leading spaces.

        xstring s=" Hello world! ";
        s.LeftSpaceTrim();//modifies to "Hello world! "
xstring xstring::LeftZeroPad ( int  how_many_zeroes  )  [inline]
Returns:
the string value padded with a specified number of zeroes on left.
        xstring a,s="Hello world!";
        a=s.LeftZeroPad(18);//returns "000000Hello world!"
        a=s.LeftZeroPad(13);//returns "0Hello world!"
        a=s.LeftZeroPad(-1);//returns "Hello world!"
        a=s.LeftZeroPad(8);//returns "Hello wo"
xstring xstring::LeftZeroTrim ( void   )  [inline]

Remove leading zeroes.

        xstring s="0Hello world!0";
        s.LeftZeroTrim();//modifies to "Hello world!0"
int xstring::Length ( void   )  [inline]
Returns:
the number of characters.
        xstring s="Hello world!";
        int len=s.Length();//returns 12
int xstring::Locate ( LPCTSTR  lpsz_to_locate,
unsigned long  start_at_byte = 0,
bool  ignore_case = __nocasesensitive 
)

Finds the first occurrence of a substring beginning at the specified position; the comparison is no case sensitive unless the parameter ignore_case is __casesensitive.

Returns:
the position of the substring found or __notfound if no occurrence is found. The position is 0 based.
        xstring s="Hello world!";
        int pos=s.Locate("llo");//returns 2
        int pos=s.Locate("wo",2);//returns 6
        int pos=s.Locate("wo",20);//returns __notfound
        int pos=s.Locate("LLO",0,__casesensitive);//returns __notfound
int xstring::LocateLast ( LPCTSTR  lpsz_to_locate,
unsigned long  start_at_byte = 0,
bool  casecheck = __nocasesensitive 
)

Finds the last occurrence of a substring beginning at the specified position; the comparison is no case sensitive unless the parameter ignore_case is __casesensitive.

Returns:
the position of the position of the substring found or __notfound if no occurrence is found. The position is 0 based.
        xstring s="-abc-def-ab-vbc";
        int pos=s.LocateLast("ab");//returns 9
        int pos=s.LocateLast("ab",4);//returns 9
        int pos=s.LocateLast("ab",30);//returns __notfound
        int pos=s.LocateLast("AB",0,__casesensitive);//returns __notfound
xstring& xstring::Mask ( unsigned char  mask_char  )  [inline]

Masks each character with a value.

xstring xstring::Middle ( int  at_char,
int  how_many_chars = -1 
)
Returns:
a specified number of characters beginning at the specified position. The position is 0 based.
        xstring a,s="Hello world!";
        a=s.Middle(0);//returns "Hello world!"
        a=s.Middle(5);//returns " world!"
        a=s.Middle(5,3);//returns "wor"
        a=s.Middle(-1,3);//returns null
        a=s.Middle(0,-20);//returns "Hello world!"
xstring xstring::nextToken ( void   ) 
Returns:
the next token(refer to startTokenize)
xstring::operator __int64 ( void   )  [inline]
Returns:
the short value produced by interpreting this object as a number.
xstring::operator char ( void   )  [inline]
Returns:
the char value produced by interpreting this object at the specified position.
xstring::operator double ( void   ) 
Returns:
the double value produced by interpreting this object as a number.
xstring::operator int ( void   )  [inline]
Returns:
the integer value produced by interpreting this object as a number.
xstring::operator long ( void   )  [inline]
Returns:
the long value produced by interpreting this object as a number.
xstring::operator short ( void   )  [inline]
Returns:
the short value produced by interpreting this object as a number.
xstring::operator unsigned char ( void   )  [inline]
Returns:
the char value produced by interpreting this object at the specified position.
xstring::operator unsigned int ( void   )  [inline]
Returns:
the long value produced by interpreting this object as a number.
xstring::operator unsigned short ( void   )  [inline]
Returns:
the unsigned short value produced by interpreting this object as a number.
xstring& xstring::Replace ( LPCTSTR  lpsz_to_find,
LPCTSTR  lpsz_to_replace,
bool  replace_all = true,
bool  casecheck = __nocasesensitive 
)

Finds and replace the first occurrence of a substring with another string; the comparison is no case sensitive unless ignore_case is __casesensitive. The position is 0 based.

        xstring s="Hello world!";
        s.Replace("Hello","Bye bye");//modifies to "Bye bye world!"
        s.Replace("HELLO","Bye bye",__casesensitive);//no modifies occurs
xstring xstring::Right ( int  how_many_chars  )  [inline]
Returns:
a specified number of characters from the right side
        xstring a,s="Hello world!";
        a=s.Right(2);//returns "d!"
        a=s.Right(-2);//returns "Hello world!"
        a=s.Right(22);//returns "Hello world!"
xstring xstring::RightSpacePad ( int  how_many_spaces  )  [inline]
Returns:
the string value padded with a specified number of zeroes on right.
        xstring a,s="Hello world!";
        a=s.RightSpacePad(18);//returns "Hello world!      "
        a=s.RightSpacePad(13);//returns "Hello world! "
        a=s.RightSpacePad(-1);//returns "Hello world!"
        a=s.RightSpacePad(8);//returns "Hello wo"
xstring xstring::RightSpaceTrim ( void   )  [inline]

Removes trailing spaces.

        xstring s=" Hello world! ";
        s.RightSpaceTrim();//modifies to " Hello world!"
void xstring::Spaces ( int  how_many_spaces  ) 

Fills with specified number of spaces; underflow checking is performed.

        xstring s;
        s.Spaces(10);//modifies to "          "
        s.Spaces(-20);underflow! No filling occurs
xstring xstring::SpaceTrim ( void   )  [inline]

Removes leading and trailing spaces.

        xstring s=" Hello world! ";
        s.SpaceTrim();//modifies to  "Hello world!"
void xstring::startTokenize ( void   ) 

Initialize this object for further search of tokens. A typical sequence of operations to get tokens from a string look like this:

        xstring xsf,tok="aaa.bbb,ccc.ddd";
        tok.delimitToken(".,");
        tok.startTokenize();
        while(tok.currentToken().isNotNull()){
                xsf+=tok.currentToken();
                tok.nextToken();
                }
        //Now the string xsf is: aaabbbcccddd
xstring& xstring::toLowerCase ( void   )  [inline]

All characters will be converted to lowercase.

        xstring s="Hello world!";
        s.toLowerCase();//modifies to "hello world!"
xstring& xstring::toUpperCase ( void   )  [inline]

All characters will be converted to uppercase.

        xstring s="Hello world!";
        s.toUpperCase();//modifies to "HELLO WORLD!"

The documentation for this class was generated from the following file:

Generated on Sun Nov 29 07:22:16 2009 for Rad.on++ by  doxygen 1.6.1