xbString Methods

Chapter Updated 8/20/03


This table lists the xbString methods.



xbString Method List API

MethodDescription
xbString()Class Constructor
xbString(size_t size)Constructor, allocates space of size
xbString(char c)Constructor, initialized to char c
xbString(const char *s)Constructor, initialized to string s
xbString(const char *s, size_t maxlen Constructor, initialized to string s, with minimal string buf size of max_len
xbString(const xbString &s)Constructor, initialized to string s
~xbString()Class Destructor
const char operator*()Returns data
char operator[](int n)Returns char in position n
xbString &operator=(const xbString &s)
xbString &operator=(const char *s)
xbString &operator=(char c)
Set string to s or c.
xbString &operator+=(const char *s)
xbSting &operator+=(char c)
Concatonate data to string
xbString &operator-=(const char *s)
xbSting &operator+=(char c)
Concatonate data and eliminate spaces between strings.
bool operator==(const xbString &) Compare string ==
bool operator!=(const xbString &) Compare string !=
bool operator<(const xbString &s) Compare string <
bool operator>(const xbString &s) Compare string >
bool operator<=(const xbString &s) Compare string <=
bool operator<=(const xbString &s) Compare string >=
xbString addBackSlash( char c )Prefixes all char c with a backslash.
xbString& assign(const xbString& str, size_t pos = 0, int len = 1)Assign data in str starting at position pos for a length of len and return a reference.
xbString& assign(const xbString& str, int len ) Assign data in str for a length of len and return a reference.
xbString copy() constUsed to copy a string
const char * c_str() constReturns the string or NULL if string is null. Depreciated function.
int countChar( char c ) constReturns the count of char c.
int cvtHexChar( char & out )Converts a four byte string in the format of 0x00 to a one byte char value out. Returns 0 on success, -1 on error.
int cvtHexString( zbString & out )Converts a string of four byte groupings in the format of 0x00 to a string of one byte characters out. Returns 0 on success, -1 on error.
char getCharacter( int n ) constReturns the character as position n.
const char *getdata() constReturns the string
bool hasAlphaChars() constReturns true is string contains any alpha characters, otherwise returns false.
bool isEmpty() constReturns true if the string has no memory allocated, or memory allocated is a zero byte string, otherwise returns false
bool isNull() constReturns true if the string has no memory allocated for the string, otherwise returns false
size_t len() const
size_t length() const
Returns length of string. It does not include the null terminating byte.
xbString mid( size_t pos, int len )Pull a string of data out of another string of data, starting at position pos for a length of len.
void ltrunc( size_t cnt )Left truncate the string cnt bytes.
int pos(char c)Locate character in string
int pos(const char *s)Locate string s in string
void swapChars(char from, char to)Swap character from to character to.
void putAt(size_t pos, char c)Put character c at position pos
void remove( size_t pos = 0, int len )Remove data from the string to starting at pos for a lenght of len.
void setNum(long num)This method sets the string to the numeric value num.
xbString &sprintf(const char * format, ... ) Used to format a string. See the standard C printf function for formatting details. Internal 256 byte buffer which can be overflowed.
void toLowerCase()Converts string to lower case
void toUpperCase()Converts string to upper case
void trim()trim trailing spaces
void zapChar( char c )Remove all instances of c from the string.
void zapLeadingChar( char c )Left truncate all of c from the string.
xbString operator-(const xbString &s1, const xbString &s2) Concatonate two strings together, eliminate spaces
xbString operator+(const xbString &s1, const xbString &s2)
xbString operator+(const xbString &s1, const char *s2)
xbString operator+(const char *s1, const xbString &s2)
xbString operator+(const xbString &s1, char c2)
xbString operator+(char c1, const xbString &s2)
Concatonate two strings together
bool operator==(const xbString &, const char *) Compare string ==
bool operator!=(const xbString &, const char *) Compare string !=



Sample program

/* string.cpp Xbase project source code This program demonstrates the usage of the xbString class Copyright (C) 1997 Gary A. Kunkel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: Mail: Technology Associates, Inc. XBase Project 1455 Deming Way #11 Sparks, NV 89434 USA Email: xbase@techass.com xdb-devel@lists.sourceforge.net xdb-users@lists.sourceforge.net Website: xdb.sourceforge.net */ #include <xbase/xbase.h> int main() { xbString s1; xbString s2; s1 = "Some string data"; s2 = "some more string data"; std::cout << "s1 => " << s1 << std::endl; std::cout << "s2 => " << s2 << std::endl; s1 = "s1 "; s2 = "s2"; s1 -= s2; std::cout << "-= operator => " << s1 << std::endl; s1 = "s1 "; s2 = "s2"; s1 += s2; std::cout << "+= operator => " << s1 << std::endl; s1 = "some data"; s2 = s1.mid( 2, 3 ); std::cout << "mid() = " << s2 << std::endl; return 0; }