Click here to Skip to main content
15,889,654 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.2K   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 
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 
"I might have understood something completely different from what you SAY you meant , but I won`t appologize because I know what you really meant ."

That's REALLY SELFISH ! So you better know what I meant than myself ? Stop being such a paranoid one, your code is the best, the most beautiful, everyone will stole it, Microsoft will hire you in minutes, you're the new Linus Torvald, you'll make the new BYTE cover for 10 months++ Frown | :(

Something wrong with ya fella ? That's your right to delete your articles if you're afraid some people might have a look at it :/ But I not accused you of stealing code, just putting some related links on your page, making it like a bookmark for me and many people.

But obviously you don't cope with critisism and competition that may faden your glory of having wrote the 1000s string library :/

Wake up of your dream, you're not the next Bill Gates, take a breath, then return hiding yourself under the claims everybody hates you, wants about your knowledge with "something called envy" !

I won't change my opinion, thanks alot, the world is better with diversity, your code is a good contribution, people have the right to know also some more works without having to google for hours, that's why I put some links...

Ho well, sorry, you know better than me why I put them here, to prove everybody you stolen the code :/ I may confess you, I'm the real right owner of the... addition, the '+', that's me who 'invented' it, everyone should bend before me !

There is no several ways to do an addition, there is not very more ways to do a string library. Some other people should have 'invented' a string library, and thus you should have 'invented' your one. That's was the REAL PURPOSE of the links, not to prove anything, just to link these 'inventions'...

Well, just have to vomit your previous brain-sick post, give me 5 minutes...

Kochise

PS : I like your code, now if I change my opinion, it would result in -> I HATE YOUR CODE ! Is that what you really want ?

In Code we trust !
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.