BetterString(void)
Constructs an empty better string equivalent to an empty string
BetterString str(); //str = ""
BetterString(std::string def)
Constructs a better string set to the standard string passed in
std::string def = "hey";
BetterString str(def); //str = "hey"
BetterString(unsigned int init)
Constructs a better string of only spaces of size init
unsigned int init = 5;
BetterString str(init); //str = " "
BetterString(const BetterString& copy)
Constructs a better string equivalent to the one passed in
BetterString copy("hello");
BetterString str(copy); //str = "hello"
char operator[](int index)
Returns the char at the given string index, -1 if index out-of-range
BetterString str("hello");
str[0]; //"h"
BetterString operator+(const BetterString& s)
Adds the two better strings together, and returns a new better string
BetterString one("one");
BetterString two("two");
BetterString three = one + two; //three = "onetwo"
void operator+=(const BetterString& s)
Adds this better stirng to the one passed in, and sets this better string to the new one
BetterString one("one");
BetterString two("two");
two += one; //two = "onetwo"
BetterString operator*(unsigned int times)
Multiplies this string the amount of times given, and returns a new better string
BetterString one("one");
BetterString two = one*3; //three = "oneoneone"
void operator*=(unsigned int times)
Multiplies this string the amount of times given and set this better string to the new one
BetterString one("one");
one *= 3; //one = "oneoneone"
bool operator==(const BetterString& s)
Returns true if this better string is equivalent to the one passed in, false otherwise
BetterString one("one");
BetterString two("two");
one == two; //false
bool operator!=(const BetterString& s)
Returns true if this better string is not equivalent to the one passed in, false otherwise
BetterString one("one");
BetterString two("two");
one != two; //true
BetterString operator-(const BetterString &s)
Removes every instance of s in this better string, and returns a new better string
BetterString test("hello");
BetterString rem("l");
BetterString sub = test - rem; //sub = "heo"
void operator-=(const BetterString &s)
Removed every instance of s in this better string and sets this better string to the value
BetterString test("hello");
BetterString rem("l");
test -= rem; //test = "heo"
void operator=(const BetterString& s)
Sets this string to the better string passed in
BetterString one("two");
BetterString two = one; //two = "two"
bool operator<(const BetterString& s)
Returns true if this better string is less than the one passed in
BetterString one("one");
BetterString two("two");
one < two; //true
bool operator<=(const BetterString& s)
Returns true if this better string is less than or equal to the one passed in
BetterString one("one");
BetterString two("two");
one <= two; //true
bool operator>(const BetterString& s)
Returns true if this better string is greater than the one passed in
BetterString one("one");
BetterString two("two");
one > two; //false
bool operator>=(const BetterString& s)
Returns true if this better string is greater than or equal to the one passed in
BetterString one("one");
BetterString two("two");
one >= two; //false
BetterString operator()(unsigned int start)
Get a substring of this better string starting at the int passed in
BetterString test("hello");
test(1); //"ello"
BetterString operator()(unsigned int start, unsigned int stop)
Get a substring of this better string starting and stopping at the ints passed in
BetterString test("hello");
test(1, 3); //"el"
BetterString operator()(unsigned int start, unsigned int stop, unsigned int step)
Get a substring of this better string starting and stopping at the ints passed in, skipping every step chars
BetterString test("hello world");
test(0, 11, 2); //"hlowrd"
friend ostream& operator<<(ostream& os, const BetterString& s)
Merges this better string with the output stream specified
BetterString test("test");
std::cout << test; //prints "test"
friend std::string operator<<(std::string s1, BetterString& s2)
Merges this better string with the string specified
BetterString test("test");
std::string merge = "merge";
merge << test; //"mergetest"
friend const char* operator<<(const char* s1, const BetterString& s2)
Merges this better string with the C-string specified
BetterString test("test");
"merge" << test; //"mergetest"
friend istream& operator>>(istream& is, BetterString& in)
Sets the better string specified with the input string passed in
BetterString test;
std::cin >> test; //input test
int size(void)
Returns the size of the better string instance
BetterString str("hey");
str.size(); //3
std::string as_str(void)
Returns this better string as a standard string
BetterString str("hey");
str.as_str(); //"hey"
const char* c_str(void)
Returns this better string as a legacy C-string
BetterString str("hi");
str.c_str(); //"hi" as C-string
std::vector<char> as_vector(void)
Returns this better string as a vector of chars
BetterString str("hi");
str.as_vector(); //vector <'h', 'i'>
BetterString subtractFirst(const BetterString& s)
Subtracts the first instance of the string specified in this better string, and returns a new better string
BetterString test("banana");
BetterString rem("a");
BetterString sub = test.subtractFirst(rem); //sub = "bnana";
BetterString lower(void)
Returns a new better string in all lowercase
BetterString test("HeY TherE");
test.lower(); //"hey there"
BetterString upper(void)
Returns a new better string in all uppercase
BetterString test("HeY TherE");
test.upper(); //"HEY THERE";
BetterString title(void)
Returns a new better string in title case
BetterString test("HeY TherE");
test.title(); //"Hey There";
int index(std::string s)
Returns the index of the string specified in this better string, -1 if not found
BetterString test("test");
std::string find = "e";
test.index(find); //1
int index(std::string s, int start)
Returns the index of the string specified in this better string, starting at start, -1 if not found
BetterString test("test");
std::string find = "t";
test.index(find, 1); //3
bool equalsIgnoreCase(const BetterString& s)
Checks if this better string is equal to the one specified, disregarding capitalization
BetterString one("one");
BetterString two("ONE");
one.equalsIgnoreCase(two); //true
iterator begin(void)
Returns the beginning of this better string's iterator
BetterString test("test");
BetterString::iterator it = test.begin();
iterator end(void)
Returns the end of this better string's iterator
BetterString test("test");
BetterString::iterator it = test.end();
iterator operator++(void)
iterator operator++(int)
Increments this iterator
BetterString test("test");
BetterString::iterator it = test.begin();
it++; ++it;
char operator*(void) const
Returns the char associated with this iterator
BetterString test("test");
BetterString::iterator it = test.begin();
*it; //'t'
This page was last edited on 10.27.2022