LinuxQuestions.org
Visit Jeremy's Blog.
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 09-27-2010, 01:28 PM   #1
faizlo
Member
 
Registered: Sep 2008
Location: USA
Distribution: Linux Mint Qiana
Posts: 190

Rep: Reputation: Disabled
check for a substring:


Hi,

I have a macro which I use with ROOT.
In this macro I want to check if a part of string exist so I can ignore it inside a loop. So, inside a loop I want to have something like:

Code:
if (string == "pre_ti_data_bdt*" || string == "pre_ti_data_nn*")
continue;
but of course I cannot use * in this piece of code!
How to do this trick in C++?

~faizlo
 
Old 09-27-2010, 01:40 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
strncmp() or whatever equivalent is in the std::string class.

Oh.. and why are you using macros? Various features of C++ almost entirely eliminate any good reason to use them.

Last edited by tuxdev; 09-27-2010 at 01:41 PM.
 
Old 09-27-2010, 01:42 PM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
You're translating from shell to C++?

man glob

Can help and good luck
 
Old 09-27-2010, 01:43 PM   #4
faizlo
Member
 
Registered: Sep 2008
Location: USA
Distribution: Linux Mint Qiana
Posts: 190

Original Poster
Rep: Reputation: Disabled
How would this be used in the above piece of code?
 
Old 09-27-2010, 01:43 PM   #5
faizlo
Member
 
Registered: Sep 2008
Location: USA
Distribution: Linux Mint Qiana
Posts: 190

Original Poster
Rep: Reputation: Disabled
Guttorm,

No I am not translating from a script.
 
Old 09-27-2010, 08:03 PM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Okay C++... what data type is your variable string? If it is a std::string then look at the function find()
Code:
if (string.find("pre_ti_data_bdt")==0))
you can change the rhs to being != std::string::npos if you want a match anywhere in the string.

Variable name of string is not ideal but maybe that was just for illustrative purposes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to substring santhoshv Linux - Newbie 3 09-09-2008 05:09 AM
seperating substring jkeertir Linux - Newbie 1 04-09-2008 12:37 AM
php preg_replace substring of a substring senyahnoj Programming 5 12-08-2006 11:31 AM
to get a substring dimah Programming 1 06-22-2006 06:31 AM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM

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

All times are GMT -5. The time now is 08:13 PM.

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