Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

.NET Cha�nes Utilitaires (String Utils)

0.00/5 (No votes)
15 Mar 2004 1  
Classes Library for String manipulations in Your .NET projects

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 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