Virtual Developer Workshop: Containerized Development with Docker

The XString-class is a powerfull extension to the standard CString-class. Whereever you use a CString you can now use a XString with much more functionality. The class includes many string-functions I missed in CString, like removing, replacing or inserting strings into another, convertingfunctions to double or int and case-insensitive find, replace and remove. But the most powerfull extension is a method I called 'Elementstrings'. Most of the functions are const and return a XString, so you can use them in an expression. The functionality of this class is not very difficult to understand or to implement, but in my case, it saves a lot of time in my projects.

If you miss some functions which could be usefull to extend this class please contact me.

Additional String functions
What are Elementstrings?
Elementstring functions
Friend functions

Download source file (8 KB) (comments in german)

Additional Stringfunctions:

Function Description Example Result
    XString num("12.345");
Double Convertion to double num.Double() 12.345
Int Convertion to int num.Int() 12
Char Convertion to char num.Char() 1
Bool Convertion to bool num.Bool() true
    XString test("Test Test");
Remove Remove first occurence of a string, char or range test.Remove('e') "Tst Test"
RemoveAll Remove all occurences of a string or char test.RemoveAll("e") "Tst Tst"
Replace Replace first occurence of a string, char or range with another string test.Replace("x", "e") "Txst Test"
ReplaceAll Replace all occurences of a string or char with another string test.ReplaceAll("x", "e") "Txst Txst"
Insert Inserts a string at a given position test.Insert("e", 1) "Teest Test"
    XString op("Test");
XString leer;
operator-- Remove last character of the string op--, --op "Tes"
operator! Indicates, wheter the string was empty !op
    XString test("Test");
Like Find, Remove or Replace, but case-insensitiv (No Case) test.Find("E")
    XString test(" Test ");
Reverse Reverses the string test.Reverse() " tseT "
Trim Delete leading and trailing whitespaces test..Trim() "Test"
Lower Returns lowercase string test.Lower() " test "
Upper Returns uppercase string test.Upper() " TEST "
    XString test("Test Test");
FromTo Like Mid, but using positions test.FromTo(5, 7) "Tes"
Count Counts the occurence of a string or char in another string test.Count('e') 2
    XString test("Test")
FindIndex Search the position of the first occurence of a char test.FindIndex('s') 2
Fill Fill the string to the specified length with trailing spaces test.Fill(5) "Test "
    XString error("Error * in Line *");
ReplaceTabs Replace all \t in the string with the corresponding number of spaces    
ReplaceText Replace '*' with specified text.
When using more than one '*' devide the replace-texts with '|'
error.ReplaceText("75|120") "Error 75 in Line 120"
    XString format("###.##");
GetDoubleFormatString Translate a formatting-string into C-notation format.GetDoubleFormatString() "%6.2lf"

What are Elementstrings?

Elementstrings are a special sort of short (and dynamic) stringarrays. Every array-entry was divided with a separator from the next entry. For example, the elementstring "zero|one|two|three" has four elemententrys. With this class you can easyly get, set or find a specified element. You don't have to specify the size of the 'array', because it's only one string. The entries can be strings, chars, doubles, ints or bools. If you set an entry, the numbers are converted into strings and if you get one, it was back converted to the specified type. Normaly the separator is '|', but it's possible to use every other character.


Function Description Example Result
    XString str("zero|one|22|3.3|four|5||7")
Element Return the given element as string str.Element(1) "one"
Elements Return the given elements as an elementstring str.Elements(1, 4) "one|22|3.3|four"
operator() same as Element or Elements str(3) "3.3"
Return the given element as specified type str.GetString(3)
SetElement Set the element at the given index with a
string, double, int, char or bool
str.SetElement(3, 99)
str.SetElement(9, 'x')
ElementIndex Retrieve the index of the specified element str.ElementIndex("four")
Sort the elementstring by using the specified type str.ElementSortString()
SetSeparator Defines a new separator XString::SetSeparator('#')  
RestoreSeparator Restores temporary separators XString::RestoreSeparator()  
    XString str("one#two#three")
You can use all functions with an additional parameter as temporar separator. str.Element(1)
str.Element(1, '#')


Function Description Example Result
itoa Create a XString from an int itoa(5) "5"
utoa Create a XString from an unsinged int utoa(2) "2"
dtoa Create a XString from a doube dtoa(3.14)
dtoa(3.14, 5)
Repeat Create a XString with copies of a given string or char Repeat('x', 10)
Repeat("Test", 3")
GetStringTableEntry Return the entry of a stringtableresource GetStringTableEntry(
Concat Create an elementstring of 1 to 16 strings Concat("This", "Is", "A", "Test") "This|Is|A|Test"


If you've questions, contact me at Joachim.Raidl@iname.com

Last updated: 8 May 1998


  • C# conversion of RemoveAll method

    Posted by davepusey on 06/04/2005 04:38pm

    I have converted the RemoveAll method to C#. Here is the source code...
    private static string RemoveAll(string Input, char CharToRemove)
      string TempString = Input;
      while (TempString.IndexOf(CharToRemove) >= 0)
        TempString = TempString.Remove(TempString.IndexOf(CharToRemove),1);
      return TempString;

  • help me~~~~

    Posted by Legacy on 05/12/2003 07:00am

    Originally posted by: Joli

     I'm beginners in programming, and studing about string.
    I made project file with MFC VC++ and this errors come out.

    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol
    Debug/XString.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.
    Creating browse info file...
    XString.exe - 3 error(s), 0 warning(s)

    What should i do? Please Help me.

  • Simple modification for use in VC++ .NET

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

    Originally posted by: Josh

    To use in VC++ .NET simply replace m_pchData with *this and replace array accesses with the GetAt function.

    • Please explain changes for VC7 .NET

      Posted by solion on 10/07/2004 05:32pm

      >replace array accesses with the GetAt function. I compiled without changing arrays, only replaced m_pchData with *this. What did you mean by replace with GetAt ? Can you give an example, please ?

  • Problems in VC++ .NET 7.0

    Posted by Legacy on 02/13/2002 08:00am

    Originally posted by: Joe

    do not use this if your in VC++ 7.0.

  • String Extension

    Posted by Legacy on 06/07/2001 07:00am

    Originally posted by: Devi

    How to convert date in String format to Date?

    For eg , a sample date string is

    "January , 05 June,2000"

  • Se puede usar en lugar de ' char * ' y ' const char* '

    Posted by Legacy on 09/28/2000 07:00am

    Originally posted by: William Gonz�les

    �Se puede usar esta clase en par�metros de funciones de tipo ' char * ' y ' const char * ' ?

    La clase CString tiene el operador ' const char* ', pero hay muchas funciones que tienen par�metros de tipo
    ' char * ' usadas para recibir en ellas una cadena de caracteres, la clase CString se puede usar aqu� con las funciones GetBuffer() y ReleaseBuffer(), pero me obliga a limitar mi cadena de caracteres a un n�mero fijo y si la cadena que voy a recibir es mas larga, empiezan los problemas.


    William Gonz�les S.

  • Comment-out "#include NoDump.h" ( Answer from Joachim)

    Posted by Legacy on 02/05/1999 08:00am

    Originally posted by: Jong-Yun Moon

    Comment-out "#include NoDump.h".

    When I asked to Joachim, he told me that it was just for debugging, so should comment-out.

  • I Don't Know....NoDump.h....Please Help Me!!!

    Posted by Legacy on 01/22/1999 08:00am

    Originally posted by: Lee Jung Ryong

    It's important work..
    I must know rapidly What "NoDump.h" is working for...
    And, Please Let me Know where to get it...
    Please Help me....

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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