LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search some numbers in a big string

Solved!
Go to solution

hi all how i can search some numbers in a big string for example string is

" 23(233)

24(456)

25(253)

i"

 

 

 

 

23,24,25 are fix numbers but others are variable numbers that i need them and i means string is over please show its block diagram i really confused with string functions !

0 Kudos
Message 1 of 7
(2,955 Views)

First, it is not clear exactly what you want. For the example string you includes, what should the output be?

 

Are there always the same number of numbers in each string or can it vary from string to string?

 

Are errors possible in your string? If so, how do you want to handle them?

 

Second, you generally will get better help if you show what you have tried, explain what kind of problems you have, and show what you want it to do.

 

One method of learning how various functions work is to write little test VIs. You could write a VI with controls for string input and search string or regular expression on the Search String, Match Pattern, and Match Regular Expression functions along with indicators on the outputs to see how they work side by side.  Regular expressions can be confusing until you have become familiar with them, but they are quite powerful.

 

Lynn

0 Kudos
Message 2 of 7
(2,951 Views)

if you are sure of the format, you can make something like attached vi

 

 

0 Kudos
Message 3 of 7
(2,940 Views)

Dear Lynn

that is true thanks

i am begginer at this i will obey your advice.

my string is exactly like this :

FF(00)

10(21322122)

11(324)

.

.

.

951(3216)

51(432)

 

 

in this string there are some names that are always same for example FF, 10, 11 ,951 and 51. these are names but numbers in Parenthesis are variable and i need them i am not sure that lines are fix or not for example mabye FF goes to line 2 or 3. now I want pick variable of 51(432) it means i need 432. notice that we have 951 befor this and if you use match pattern and write "51(*" it find 951 now what can i do?


regards

0 Kudos
Message 4 of 7
(2,903 Views)

Does your string have carriage returns or line feeds at the end of each line, or did you just display it that way for convenience?  If it has End of Line characters, then it can easily be converted to an array of strings.  Each element will contain only one line and thus only one number.  For each line search for the parentheses ( ).  The number you want is between them.

 

Even if you do not have End of Line characters, I would search the string for pairs of parentheses and get the data that way.

 

Lynn

0 Kudos
Message 5 of 7
(2,881 Views)
Solution
Accepted by topic author 12321254

This is the kind of problem that can be solve using regular expressions. The ^ anchors the match at the beginning of a line, so if you enter 51 in Search string control the resulting regex will be ^51\((\d+)\). The match regex function will look at a line starting with 51 [so 951 is not a match], followed by (, The (\d+) inner most parameter is a capture group containing one or more numeric character [you have to extend the bottom of the match regex function to get the output of the capture group] and finally the closing ). The opening and closing parentheses must be preceded by the escape character \ because they are special characters.

 

In this case I supposed that the string is composed of multiple lines.

 

Ben64

 

RegexSearchString.png

0 Kudos
Message 6 of 7
(2,864 Views)

thanks ben that is exatcly what i need

0 Kudos
Message 7 of 7
(2,834 Views)