Check for a substring


 
Thread Tools Search this Thread
Top Forums Programming Check for a substring
# 1  
Old 09-27-2010
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
# 2  
Old 09-27-2010
If you only care about the data prior to "*", then you can use "strstr()" which checks if your string contains that data.
# 3  
Old 09-27-2010
Hi,

I care about the whole sentence, meaning I want any string that contains this part "pre_ti_data_bdt" to be passed without being calculated through the rest of the loop
# 4  
Old 09-27-2010
See man strstr.
# 5  
Old 09-27-2010
Well that should work then. If you see the occurrence of "pre_ti_data_bdt" then continue....i.e.

Code:
if(strstr(string_you_want_to_parse,"pre_ti_data_bdt") != NULL))  // pre_ti_data_bdt in string
  continue;

# 6  
Old 09-27-2010
strstr() depends on making the comparison between the part of the string, substring, and the string name. I have hundreds of these string names and I only want those that do not contain this part "pre_ti_data_bdt" or this part "pre_ti_data_nn" to go through the whole loop.
# 7  
Old 09-27-2010
Quote:
Originally Posted by faizlo
strstr() depends on making the comparison between the part of the string, substring, and the string name.
I'm not sure what you're saying here. strstr hunts for an instance of one string inside another, precisely what you want. If you want to check for two strings, call it again on the other string, and skip if either match.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if string contains substring surrounded by numbers

Hi, I have a process that generates strings. I would like to check each string and search for substring which contains the letter 'E' surrounded by numbers (both sides of the letter 'E'). few examples: AA4E7012A2 - contains E surrounded by numbers FE18274012 - does not contain E... (3 Replies)
Discussion started by: yanive
3 Replies

2. Shell Programming and Scripting

Substring check in IF condition in shell script

I want to check if the string has the substring in IF condition then process... i tried below but not working if ]; then ............. field can be "reserved1" ....reservedn / fillspaces1 ... fillspacesn (4 Replies)
Discussion started by: greenworld123
4 Replies

3. Programming

check substring

hi everyone I have a C program where I have a line and I want to check if the line contains a string.The line is stored in a buffer.How can I do that? Can I consider the whole line as a string and check for a substring?And if so what's the most efficient way to achieve it? (1 Reply)
Discussion started by: vlm
1 Replies

4. Shell Programming and Scripting

Get the substring

Hi All, I have a ouput string likes 'u8wos' or 'u10acsd' or somthing else 'u{number}{any characters}'and I want to get the number behind the letter 'u' by bash shell. Thanks Damon (11 Replies)
Discussion started by: Damon_Qu
11 Replies

5. UNIX for Dummies Questions & Answers

Getting Substring

Hi, I hav a string lets say aa.txt:bb:txt length of the string can vary.. I have to keep the token inside a array and the delimiter is : plz send me the code (2 Replies)
Discussion started by: Deekay.p
2 Replies

6. Shell Programming and Scripting

substring

I have a string '<Hi>abc</Hi>" How to print "abc" (6 Replies)
Discussion started by: sandy1028
6 Replies

7. UNIX for Dummies Questions & Answers

Substring

Hi I use the below cmd to get the list of files that are modified than <temp> file in the <path> diretory cmd:find <path> -name '*.zip' -type f -newer <temp> -print i am getting all the list of files that are new or modified, with abs path, i want to copy all of these files to a... (3 Replies)
Discussion started by: Naveen_5960
3 Replies

8. UNIX for Dummies Questions & Answers

Need help with substring

I need to check the occurrence of one string within another. code ******************** if ;then do something done ******************** Thanks (7 Replies)
Discussion started by: w020637
7 Replies

9. Shell Programming and Scripting

how to get substring

i have a strings abc-def.csv ghi-jkl.csv i want to make it as abc-*-def.xyz ghi-*-jkl.xyz How to do it?. (5 Replies)
Discussion started by: senthilk615
5 Replies

10. Shell Programming and Scripting

Getting a substring

This is probably pretty simple butI'm not sure how to best go about it. If I have FILE="myBigLongFileName_1.xls" FILE_PREFIX=`echo $FILE| cut -d"." -f1` # that gives "myBigLongFileName_1" All i want to do now is chop the "_1" from the end of $FILE_PREFIX Any ideas anyone? (3 Replies)
Discussion started by: djkane
3 Replies
Login or Register to Ask a Question