LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search a String within another string

Hi All

I have an application wherein I am trying to search StrA in StrB where StrA can be greater in length than StrB.

For Eg: StrA: Hot Bucket water spills.

StrB: New bucket

 

So I need to check if StrA any part is present in StrB. If the match is found then I will be doing further processing logic . I have checked with match pattern , regular expression, search/split functions , however not getting the expected output since StrA and StrB values can vary a lot. Also converting string to Array and then compare is not an option since these processing is only a initial part of application and needs much processing later.

I would like to implement a function which should be able to check if string one part is present in another string, then match should be found. 

 

0 Kudos
Message 1 of 8
(2,755 Views)

Match pattern is the faster string search. You can do as you said put it in a array and then in a for loop do the search. the for loop can execute in parallel multiple search and then you will have an array of Boolean or what ever you want as output. Then do the rest of the processing depending of the results.

Benoit

0 Kudos
Message 2 of 8
(2,750 Views)

So you have StrA as a list of words you want to search for in StrB?  If that is correct, then use Spreadsheet String To Array with a space as the delimiter to create a 1D array of strings (words).  You can then use a FOR loop to perform the Match Pattern on each element.  Turn on the conditional terminal and you can stop the FOR loop as soon as a match is found.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 8
(2,722 Views)

Search a String with in another.png

Omar
Message 4 of 8
(2,686 Views)

Where do the two strings come from? Is one static? It seems you want case insensitive match. Are there other delimiters besides space (comma, period, question mark, tab, double-space, etc.)?

 

Under some some scenarios, a variant attribute based solution might be best.

0 Kudos
Message 5 of 8
(2,672 Views)

Hi LV_user1

Do you mean like this?


Day@
Certified LabVIEW Associate Developer
0 Kudos
Message 6 of 8
(2,664 Views)

@hidayatmaulud wrote:

Hi LV_user1

Do you mean like this?


Seems extremely inefficient. For example if the two strings have very different word count, one will have many elements with empty strings. The middle code makes no sense because both array have the same number of elements guaranteed. The shift register in the second loop makes no sense because the content never changes.

Try to find a solution with 20% of the code. 🙂

 

 

 

Message 7 of 8
(2,657 Views)

Thank you for correcting me..

I'll improve my programming skill


Day@
Certified LabVIEW Associate Developer
0 Kudos
Message 8 of 8
(2,651 Views)