LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

select letters from file and store them in an array

Hi all,

 

I want to read out letters and numbers from a textfile and store them in seperate arrays. My file looks like this: -23,-33,""-15,-19"N", (and so on, so it's always two numbers and one referencecomment, which I want to have in the same row of the arrays) . So I've tried it with the Spreadsheet String To Array Funtion, but with this I'm only getting the numbers (because they are seperated with , ) I would like to have the two numbers in a 2D array and the referencecomment in a 1D array.

My idea is now to search the string for " and save the next item in an array, but there's than the problem, that I also need the empty spaces ("") in the array. Now I am quite uninspired and hope you can help me.

 

Thanks

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

Hi Bianca,

 

My file looks like this: -23,-33,""-15,-19"N", (and so on,

So there is:

- sometimes a comma before the quotation marks - and sometimes not (?)

- sometimes a comma after the quotation mark and the next number - and sometimes not (?)

 

Can you provide a VI (LV2017 preferred) with some example text in a string constant to clarify your requirements?

 

Having a comma as delimiter char used in general would make it quite easy:

check.png

(Just to give an idea. Apply conversion from string to numbers, transposing the numeric array, and stripping of the quotation marks on your own.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(2,708 Views)

Hi Gerd, 

 

thank you for your reply. My problem is, that I am not allowed to manipulate my file. So, as you already said, there is sometimes a positive and sometimes a negative number after the quotation mark, but there is never a comma.

 

My idea is to search the string for the quotation mark and then save the element after it (so index +1) into an array or something like this. I will try this.

Of course I would prefer an easier and nicer way to do this but I think it will not work with the Spreadsheet String To Array function, because I would only need the field between "" and that is not working. (I just used 2 Spreadsheet String To Array functions, so one for the numbers and the other one for my letters, but it's also not working). I added a part of my LabVIEW program so I hope it's a little bit easier to understand what I mean. I hope you can help me. 

Thanks. 

 

Best regard, 

Bianca

0 Kudos
Message 3 of 8
(2,680 Views)

Hi Bianca,

 

you still don't provide an example of your textfile in an attachment.

 

So, as you already said, there is sometimes a positive and sometimes a negative number after the quotation mark, but there is never a comma.

In your first message there's a comma after the quotation, so please provide an example we can work with!

 

Suggestion:

Separate the strings by the comma delimiters.

Then check each string for quotation marks to separate number and comment…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 8
(2,678 Views)

Hi, 

 

I'm sorry, I forgot. I added an example. I hope it worked.

 

Br,

Bianca

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

Salut,

ai incercat cu functia Match Pattern?

0 Kudos
Message 6 of 8
(2,671 Views)

Hi Bianca,

 

your problem is so easy to solve because there are Linebreaks in the text! You should have posted that example much earlier - and you should have used a real text editor like Notepad++:

check.png

 

 

Suggestion:

check.png

- Read the text as spreadsheet with a comma delimiter

- convert the first two columns to numbers

- strip the quotation marks from third column items (you may use any RegEx/MatchPattern you like instead of my approach)

- build an array of cluster with all the information…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 8
(2,668 Views)

Thanks, that helped me a lot. 🙂

 

 

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