Click here to Skip to main content
Licence GPL3
First Posted 7 May 2006
Views 18,700
Bookmarked 8 times

String Utils

By | 7 May 2006 | Article
Simple utilities to manage strings. Specially devoted to VB backgrounders

Introduction

To those used to manage strings in VB, the existance of functions like Split, Join, Replace and the like makes programming a bliss. C++ programmers don't have those "built in" facilities. For them, the present set of functions attemps to accomplish the same goal.

Matter gets worse for C++ programmers because besides the lack of those functions, they usually have to struggle with many kinds of strings (C like strings, STD strings, BSTRS, CStrings, etc). The idea is to bring a unified set of tools to cope with them all. Thus, the present tools resorts to the use of templates, allowing this way to receive as input anything that can be used to construct a std::string. There are also a couple of template specializations to deal with single charactters. A secondary goal is to show the use of template functions and namespaces.

Using the code

The following code snippet should be self explanatory:

//StringUtils::Split usage
const char* szToSplit = "Hello|World|from|String|Utils";
std::vector<std::string> v = StringUtils::Split(szToSplit, "|");

for (size_t i = 0; i < v.size(); i++)
      std::cout << v[i] << std::endl;

//StringUtils::Join usage
std::string s = StringUtils::Join(v,"#");
std::cout << s << std::endl;
//should produce: Hello#World#from#String#Utils


Enough words for now, all you've gotta do is to #include "stringutils.h" in your source code. Happy templating!

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Ernesto Savoretti

Web Developer

Argentina Argentina

Member

Born in Rosario, Argentina.
Interested in system programming, Internet apps, real time apps. Recently became Python evangelist.
Favorite tools: Python, C++, C#, Java (in that precise order)
Fluent in SQL, COM, ATL-WTL
Enjoy playing chess games, specially tournament games, and walking when I'm not programming.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralLeft() Right() Mid() and Mid()= Pinmemberhpfx23:33 6 Aug '07  
QuestionBug in Split? PinmemberAnders Dalvander23:41 7 May '06  
AnswerRe: Bug in Split? PinmemberSandy9810:43 8 May '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 7 May 2006
Article Copyright 2006 by Ernesto Savoretti
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid