0

I am looking for a way to remove all numbers and letters in brackets, as well as numbers not associated with a letter (i.e. I want to keep 'v2' or 'vol.2').

For instance:

"My Notes v02 003 (2009) (My sillyness)"

would become:

"My Notes v02".

I have found ways to remove the data in the braces and the braces themselves, however the issue I have now is removing the numbers not associated with a volume identifier.

Currently I have:

QString myItem = "My Notes v02 003 (2009) (My sillyness)";
myItem = myItem.remove( QRegExp( "\\[.*\\]|\\(.*\\)" ) );

Do I need to break the strings up into individual words and check manually? Or is there a better solution?

Wouter J
  • 41,455
  • 15
  • 107
  • 112
Eric
  • 1
  • 1

1 Answers1

0

first i want recommend you to use boost library to manipulate your string data easily http://www.boost.org/ so if your QString myItem is always struct data, it is easy to get what you want using split your string every time you find blank

#include <boost/algorithm/string.hpp>
using namespace std;
using namespace boost;
/..
QString myItem = "My Notes v02 003 (2009) (My sillyness)";
vector< string > newItem;
split( newItem, myItem.tostdstring, is_any_of(" "));
cout <<newItem.at(0) <<" "<<newItem.at(1) <<" "<<newItem.at(2) <<endl;
Moad Meftah
  • 211
  • 3
  • 7