LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to search a string backwards?

Hi,
 
I have the need to look for a char (or string) which is expected before a known postion.  Is there a function to do it?
 
for example:    strA = "abcdefg%abcdefg"
I find the location of %, now I want to know the location of "cd" that occure befor %
 
Thanks
Rafi
0 Kudos
Message 1 of 5
(4,651 Views)

Try: FindPattern(); its in the Formatting and I/O library.

JR

Message 2 of 5
(4,649 Views)

Hi and thanks

I know this function and to the best of my knowledge, it can only look for a pattern from a specified index and on....

My request was to find the pattern from a certain index and backwards....

Any idea?

 

Thanks

 

0 Kudos
Message 3 of 5
(4,645 Views)

FindPattern can search from right starting not from end of string but from an intermediate point, specified in Number of bytes parameter. For example look at this snippet of code:

char  string[32];

strcpy (string, "abcd12bcefg12abcdefg");
FindPattern (string, 0, FindPattern (string, 0, -1, "12", 0, 1), "bc", 0, 1);

it returns 6 which is the index of "bc" that appears before the second "12" (or to the left of the first "12" from right). The second FindPattern searches for the max lenght of string to scan, the first one scans this part of the string from right.

Message Edited by Roberto Bozzolo on 11-09-2006 03:35 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(4,644 Views)
you may also have a look at RegExpr_FindPatternInText () which is part of the regexp.fp instrument - a very powerful and versatile search function.

--
Once the game is over, the king and the pawn go back into the same box.
0 Kudos
Message 5 of 5
(4,615 Views)