LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-26-2010, 01:14 PM   #1
miamagoo
Member
 
Registered: Jun 2010
Posts: 32

Rep: Reputation: 15
String manipulation C++


Hi,

I need to read a file and parse a string. I know in Perl there is the split command. Is there something similar to that in C++?
 
Old 07-26-2010, 08:49 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You seek a string tokenizer. In C there was strtok, in C++ you can use the STL string tokenizer. Here is the first link I found on Google:

http://oopweb.com/CPP/Documents/CPPH...g-HOWTO-7.html
 
Old 07-26-2010, 09:01 PM   #3
m_pahlevanzadeh
Member
 
Registered: Sep 2002
Location: Iran/Tehran
Distribution: Debian
Posts: 94

Rep: Reputation: 28
if you need to create the config file for your program, you should use following library:
http://www.hyperrealm.com/libconfig/
 
Old 07-27-2010, 08:46 AM   #4
mattca
Member
 
Registered: Jan 2009
Distribution: Slackware 14.1
Posts: 333

Rep: Reputation: 56
Shouldn't this be in the programming forum?
 
Old 07-28-2010, 01:00 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by mattca View Post
Shouldn't this be in the programming forum?
Yes and I've reported it to be moved there. You're encouraged to report threads to be moved if they're in the wrong place.
 
Old 07-31-2010, 07:26 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Moved to Programming
 
Old 07-31-2010, 12:55 PM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
here's my split to get you started.
takes a perl regex, in C++ all backslashes
must be doubled up, e.g "\s" must be "\\s"

Code:
template <class T>
int split(T& container, string s, string pat="\\s+")
{

    boost::regex reg(pat);
    boost::sregex_token_iterator it(s.begin(), s.end(), reg, -1 );
    boost::sregex_token_iterator end;
    int count = 0;

    for ( ;it != end; ++it, ++count ) {
        container.insert(container.end(), *it);
    }
    return count;
}

Last edited by bigearsbilly; 08-02-2010 at 06:35 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
string manipulation jtag Linux - General 9 02-01-2010 08:07 AM
String manipulation in C xeon123 Programming 2 10-17-2007 01:17 PM
String manipulation Manuel Alvarado Linux - Newbie 2 09-06-2006 09:49 PM
string manipulation mannahazarika Programming 6 12-31-2005 11:02 AM
String manipulation with a script? philipina General 1 03-15-2004 12:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration