Click here to Skip to main content
15,880,972 members
Articles / Programming Languages / C++
Article

Ultimate String and String-List classes

Rate me:
Please Sign up or sign in to vote.
2.45/5 (20 votes)
5 Feb 20052 min read 79.1K   269   8   26
String and String-List classes compatible with both ASCII and UNICODE strings.

Warning: This has been built using VS.NET 7.1. If you can't handle some errors due to default parameter values and some minor thing, don't bother. Read the discussions for more info.

Introduction

No matter what you code, you will always bump into string management and everyone knows that sometimes it can really be a pain in the ... you know. Well, this article hopes (and I think it succeeds) in making the whole thing easier.

Description

The code presented in this article has the next goals to achieve:

  • Manage both UNICODE and ASCII strings and string-lists.
  • Provided tools for simple conversion between them.
  • Provide a simple wrapper to allow working with them.

Let's go to the next level.

Classes Details

The code contains the following classes with their functions:

  • plStringT

    This class is a template class with one param szBlock. The size of the plStringT used memory will always be a multiple of szBlock. When a memory of szBlock is allocated then, as long as the string's length doesn't top this value no memory will be allocated. This is for performance.

    Internal functions are self explanatory and there's no point in describing all the 125 of them.

  • plStringList

    This class is for managing string-lists.

    Internal functions are self explanatory and there's no point in describing all the 49 of them.

  • plToStringW, plToStringA, plToStringB, plToString

    These are helping classes. Used for conversion.

    Internal functions are self explanatory and there's no point in describing all of them.

  • plArrayT, plPointerT

    These are helping classes. An array and a pointer array. The pointer array can also free pointers on deletion.

    Internal functions are self explanatory and there's no point in describing all of them.

How to...

Some how-to points:
  • Append a formatted string:
    plString string;
    string+=plString(_T("%d %s"),100,_T("string"));
    
  • Load a file (UNICODE or ASCII):
    plString string;
    string.Load(_T("anytypeoffile.txt"));
    
  • Save a UNICODE file:
    plString string;
    string.Save(_T("anytypeoffile.txt"),0/*append*/,1/*UNICODE*/);
    
  • Append ASCII string:
    plString string;
    string+=plToString("ascii stuff %d",1000);
    
  • Read all lines:
    plString Lines;
    plString Line;
    INT Pos=0;
    while(Lines.ReadLine(Pos,Line))
    {
       _tprintf(_T("%s\r\n",Line.GetString());
    }
    
  • Split a text into lines:
    plString Lines;
    plStrings lstLines;
    lstLines.SplitText(Lines,_T("\r\n"),0);
    

Once you get a hold of it you'll be able to do anything. Easy, huh?

History

  • 05.02.2005

    First release.

  • 07.02.2005

    Fixed some bugs in plArrayT.

For any problems contact me or write here and I`ll look into them quickly . I use this classes extensively and I need them in best shape.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
I have been programming for the past 6 years in VBasic, Delphi, C, C++ .
I also have extended knowledge of webdesign (HTML, CSS, JavaScript, VBScript), webprogramming (PHP, ASP, ASP.NET (C#)) and database integration (mySql, MSSQL Server).
And when I`m not programming I`m working out or working on some personal projects .
Last but not least I`m looking for a project-based job in programming or webdesign .

Comments and Discussions

 
GeneralTwo Words Pin
Phil Harding10-Feb-05 3:37
Phil Harding10-Feb-05 3:37 
GeneralRe: Two Words Pin
verger6-Oct-05 21:11
verger6-Oct-05 21:11 
GeneralSample will not compile in C++ 6.0 Pin
JCrane27-Feb-05 5:51
JCrane27-Feb-05 5:51 
GeneralRe: Sample will not compile in C++ 6.0 Pin
TomKat7-Feb-05 7:00
TomKat7-Feb-05 7:00 
GeneralRe: Sample will not compile in C++ 6.0 Pin
JCrane27-Feb-05 9:09
JCrane27-Feb-05 9:09 
GeneralRe: Sample will not compile in C++ 6.0 Pin
TomKat7-Feb-05 10:05
TomKat7-Feb-05 10:05 
GeneralRe: Sample will not compile in C++ 6.0 Pin
JCrane27-Feb-05 11:07
JCrane27-Feb-05 11:07 
GeneralRe: Sample will not compile in C++ 6.0 Pin
TomKat7-Feb-05 11:41
TomKat7-Feb-05 11:41 
GeneralRe: Sample will not compile in C++ 6.0 Pin
JCrane27-Feb-05 14:49
JCrane27-Feb-05 14:49 
GeneralRe: Sample will not compile in C++ 6.0 Pin
TomKat8-Feb-05 0:17
TomKat8-Feb-05 0:17 
GeneralRe: Sample will not compile in C++ 6.0 Pin
rocky_pulley9-Feb-05 16:35
rocky_pulley9-Feb-05 16:35 
Just ignore people who complain constantly and you'll live a much happier life. If they have problems, offer a little advice and let them take it from there, but flaming back and forth will do nothing for you but get you bad ratings. I'd also suggest removing the "go learn a bit more" in the warning at the top, it just makes you look bad, insulting people doesn't do anyone any good. Wink | ;)

-- Rocky Dean Pulley
GeneralRe: Sample will not compile in C++ 6.0 Pin
TomKat9-Feb-05 19:55
TomKat9-Feb-05 19:55 
GeneralRe: Sample will not compile in C++ 6.0 Pin
rocky_pulley10-Feb-05 3:50
rocky_pulley10-Feb-05 3:50 
GeneralI Will try Pin
ThatsAlok5-Feb-05 19:50
ThatsAlok5-Feb-05 19:50 
GeneralRe: I Will try Pin
ThatsAlok19-Feb-05 5:41
ThatsAlok19-Feb-05 5:41 
GeneralAnother ones completely hand written... Pin
Kochise5-Feb-05 5:12
Kochise5-Feb-05 5:12 
GeneralRe: Another ones completely hand written... Pin
TomKat5-Feb-05 5:22
TomKat5-Feb-05 5:22 
GeneralThese projects... Pin
Kochise5-Feb-05 5:50
Kochise5-Feb-05 5:50 
GeneralRe: These projects... Pin
TomKat5-Feb-05 6:04
TomKat5-Feb-05 6:04 
GeneralYou made me fun ! Pin
Kochise5-Feb-05 9:03
Kochise5-Feb-05 9:03 
GeneralRe: You made me fun ! Pin
TomKat5-Feb-05 9:39
TomKat5-Feb-05 9:39 
GeneralRe: You made me fun ! Pin
Jeremy Falcon5-Feb-05 11:26
professionalJeremy Falcon5-Feb-05 11:26 
GeneralRe: You made me fun ! Pin
TomKat5-Feb-05 13:49
TomKat5-Feb-05 13:49 
GeneralRe: You made me fun ! Pin
Jeremy Falcon6-Feb-05 16:39
professionalJeremy Falcon6-Feb-05 16:39 
GeneralYes, I'm a long haired man ! Pin
Kochise5-Feb-05 11:40
Kochise5-Feb-05 11:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.