A Super String Class

Yet another string class?

This class got its start a number of years ago. At that time, it was common to have to write even the simplest data structure class. Since then it has gradually grown and mutated at irregular intervals. The result is fairly ambitious, for a string class.

Super String features string and buffer operations, conversions and comparisons, extensible searching, and C compatibility.

The complete documentation is here.

Here is the header, implementation, and example code. These are marked-up html files and so are fairly large.


Here is some code to demo the various parts of the class:

		// assign a string some values

		SS ss ("hello");

		// the new value is "65" not "A"

		ss = 65;

		// the new value is "65c"

		ss += 'c';
		// allocate a buffer

		SS ss (SS::Buffer(6));

		// indexing, length() and size() are the same

		for (int i=0; i<ss.length(); i++) ss[i] = 'a' + i;

		// substring, the current value is "abcdef"

		ss (2,3) == "cde";

		// the new value is "ab12f"

		ss (2,3) = "12";

		// the new value is "abxyf"

		ss.set ("xy", 2);

		// the new value is "abf", "xy" is returned

		ss.cut (2, 2) == "xy";

		// now back to "abcdef"

		ss.paste ("cde", 2);

		// fill with x's, "xxxxxx"

		ss.fill ('x');
		// comparisons

		SS ss(12);

		// 12 is less than 13

		ss < 13;

		ss = "one";

		// "three" is greater than "one"

		"three" >= ss;
		// searching

		SS ss ("The next one");

		// find the word "next"

		int p = ss.findNext ("next");

		// can't find the word "first"

		p = ss.findNext ("first"); // p == SS::notfound

		// find the first whitespace character

		p = ss.findNext (SS::whitespace);

		// find the next whitespace character

		p = ss.findNext (SS::whitespace, p + 1);

		// find the word "one"

		SS result;
		ss.findNext (SS::FindOneOrMore (SS::blackspace), p, result);
		result == "one";

		// ss contains "The"

		bool b = ss.contains ("The"); // b == true

		// there are 9 lowercase characters

		int n = ss.population (SS::lowercase); // n == 9

		// remove whitespace, ss is now "Thenextone"

		ss.remove (SS::whitespace);

		// replace the 'T', ss is now "thenextone"

		ss.replace (SS::uppercase, "t");

		std::cout << "the string is \"" << ss << "\"" << std::endl;
		// numeric

		SS ss ("100");

		// extract the number 100

		long v = ss.toLong();

		// create a base 16 string

		SS::toBase (v, 16) == "64";
		// matching

		SS ss ("theOne1 theTwo2 theThree3");

		// an empty vector for results
		// each element will be a position and a length

		SS::BegLenVect result;

		// get positions of all the "the"s

		ss.match ("the", result);

		// reverse the "the"s

		ss.reverse (result) == "ehtOne1 ehtTwo2 ehtThree3";

		// remove the now reversed "the"s

		ss.removeRange (result) == "One1 Two2 Three3";

		// break up into tokens, reusing result

		ss.tokenize (result);

		// change string to "One1 Two2 Four4"

		ss (result[2]) = "Four4";

		// get a vector with the digits

		ss.match (SS::digit, result);

		// cut the '4'

		ss.cut (result[2]);

		// remove the '2' by limiting the remove range

		ss.remove (SS::digit, result[1]);

		// remove the 1 via an 'X'

		ss.fill ('X', result[0]).remove ('X') == "One Two Four";

		std::cout << "the string is \"" << ss << "\"" << std::endl;

CString compatibility

Support for additional types can be added externally to the class. A header file, "QString.h", is provided to supply compatibility for CString. To allow a CString to convert to a Super String:

typedef SS QString;

inline void SSconvert (CString const & u, QString & w)
	w.assign ((char const *)u, u.GetLength());

A Super String can convert to a CString via operator char*. To allow relational comparisons, e.g. ==, >, etc. define:

inline int SScompare (QString const & u, CString const & w)
	return u.compare((char const *)w,w.GetLength());


The source and test code have been compiled with VC6.0, sp2. The only things Microsoft-specific should be the numeric type __int64, often referred to as long long, and _vsnprintf, a variant of sprintf.

To do

Possible performance enhancements, UNICODE support.

Download source + doc + demo proj + test code - 62 KB

Download source only - 24 KB


  • Alvorlige salg høykvalitets hodetelefoner av Dr. Dre

    Posted by mantouhmmm on 06/04/2013 09:28am

    [url=http://www.beatsbydrestudio.moonfruit.com/]beats by dre studio[/url] Dette rolig, beskyttelser utskiftbart hode sammen med smørbare hodebånd forsikrer bemerkelsesverdig letthet i mange år av sin tid sammen med en helt beskyttet sunt. Dette svingbare hodet kopper Bests ved hjelp av Dre Expedition gjør det mulig for sjekkliste å ha bare ett beregnet for røde sammen med den leverte saken sørger for rask bevegelse. Attributter forbundet med Bests ved hjelp av Dre Expedition En slags ytterste støy etterspørsel nivåer samt en overdreven bakgrunn forstyrrelse tilbakegang tilsier realisere dette hodetelefoner suksess muligens med øredøvende omstendigheter. [url=http://www.beatsstudionorge.weebly.com/]beats studio[/url] Once du har lastet ned flere beats, og du er fornøyd med beats som du har lastet ned. Da er det tid kompilere og polere opp på beats når beats er godt arrangert, og lyden er god, og du har spilt den om og om igjen, og du er fornøyd med det endelige produktet så er du god til å go.Once dine beats er klar så er det på tide å dele dine sluttprodukter med venner og familie. Det er også anledning til å lansere deg som en rap artist gjennom å tilby gratis rap beats og selge rap musikk på nettet. Dette gjelder også andre sjangere av musikk som du oppretter gjennom gratis online beats nedlasting. [url=http://www.monsternobeats.350.com/]monster beats[/url] Dette kan gjøres grundig lage et nettsted som du kan koble til de ulike sosiale nettverkene, og dette vil snart lansere musikken din karriere ved hjelp av svært enkel online nedlasting av beats online.Nothing kommer enkelt og så lett som det høres laste ned beats på nettet og gjøre dem til prisvinnende musikk trenger tålmodighet og konsistens i creating.Are du en spirende musikk artist som nettopp har begynt, og ute etter kvalitet instrumentaler på nettet? Er du ute etter å finne en nettside som du kan stole på og komme tilbake til igjen og igjen for radio klar instrumentaler? Er du ute etter en produsent eller beat maker som er profesjonell og vennlig? Hvis dette høres ut som deg jeg kommer til å gi deg 4 tips om hvordan du kan vite om en beat nettsted er trygt å kjøpe beats fra.

  • Nothing but errors.

    Posted by Legacy on 03/18/2003 12:00am

    Originally posted by: Nathan M.

    I cannot get your super string to even compile. All I get is error after error:

    superstr.cpp(22) : warning C4005: 'ErrorMacro' : macro redefinition
    superstr.cpp(20) : see previous definition of 'ErrorMacro'
    superstr.cpp(3561) : fatal error C1010: unexpected end of file while looking for precompiled header directive

    This thing isn't worth the trouble.

  • Link error with eVC

    Posted by Legacy on 08/08/2002 12:00am

    Originally posted by: Terry

    First when I look at this SuperClass I found that it is very useful, so I am trying to apply it to my C program written in Embeded Visual C. I understand eVC is not 100% compatable to VC, would you help me to address these problem.

    Compiling resources...
    Generating Code...
    TestStringDlg.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall SS::~SS(void)" (??1SS@@UAE@XZ) referenced in function "protected: void __thiscall CTestStringDlg::OnButton1(void)" (?OnButton1@CTestStringDlg@@IAEXXZ)
    TestStringDlg.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall SS::destroy(void)" (?destroy@SS@@MAEXXZ)
    TestStringDlg.obj : error LNK2019: unresolved external symbol "void __cdecl SSconvert(char const *,class SS &)" (?SSconvert@@YAXPBDAAVSS@@@Z) referenced in function "public: __thiscall SS::SS(char const (&)[6])" (??0SS@@QAE@AAY05$$CBD@Z)
    TestStringDlg.obj : error LNK2019: unresolved external symbol "protected: void __thiscall SS::_zero(void)" (?_zero@SS@@IAEXXZ) referenced in function "public: __thiscall SS::SS(char const (&)[6])" (??0SS@@QAE@AAY05$$CBD@Z)
    X86Dbg/TestString.exe : fatal error LNK1120: 4 unresolved externals
    Error executing link.exe.

    TestString.exe - 5 error(s), 0 warning(s)

  • Efficient code

    Posted by Legacy on 11/25/2001 12:00am

    Originally posted by: Haribaskar

    Code is written in an efficient way

  • Won't Compile

    Posted by Legacy on 02/04/2000 12:00am

    Originally posted by: Jeff WIlliams

    I can't get my code to compile properly with the SuperString added in

    when I try to compile SuperString.cpp I get the following error:

    c:\program files\microsoft visual studio\vc98\include\superstr.cpp(22) : warning C4005: 'ErrorMacro' : macro redefinition
    c:\program files\microsoft visual studio\vc98\include\superstr.cpp(20) : see previous definition of 'ErrorMacro'

    any ideas on what I'm doing wrong?

  • Great job!

    Posted by Legacy on 09/09/1999 12:00am

    Originally posted by: Rick Lawson

    Using this class heavily in an industrial hardware interface program. Handles all the string chores (coming from the GUI) very nicely.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date