LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search/replace multiple text in file

Hello:
I have been searching for vis that will search and replace double values in a text file. I have made my own that sort of works by taking a 1d array of strings I'm using for "keys" and an array of doubles that I want to substitute for the line with the key.
There has GOT to be a packaged one but I can't find one that does all. Thanks
0 Kudos
Message 1 of 7
(5,038 Views)
Did you define your own format for the text file? Since you're talking about keys and values, it sounds similar to an INI file. LabView has functions and examples to read and write INI files. If you can adapt your app to using a standard format INI file, look at the Write Configuration Settings.vi and Read Configuration Settings.vi examples that ship with LabView. The INI file functions are on the File I/O >> Configuration File VIs palette.
0 Kudos
Message 2 of 7
(5,038 Views)
You can use the scan from string function in the strings subpalette. This will allow you to parse out numbers. Also you can read in your file as a spreadsheet string and convert your spreadsheet string into an array. If the other info in the file doesn't change you will always know what index your numbers are in and then can change them using the replace array element and a number to string conversion. There can be a few different ways to do this but there is no vi that I know of that does all of this. Hope this helps.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
0 Kudos
Message 3 of 7
(5,038 Views)
thanks, but the file I'm dealing with is a file that will contain original cal values that I don't want the user to recreate. I.E. I cannnot use the config vis to read it as there are no set "keys".
I was able to coble together a vi to do what I want using Match Pattern vi and concatonate strings.
0 Kudos
Message 4 of 7
(5,038 Views)
Thanks for your suggestions. I had to read in each line, use match pattern vi to see if is the line I needed to change, pick the substring to search for off a hardcoded 1d str array, then substitute the new value (also a 1d array)for the old one.
I could show you if interested. An example of the input file is:
40K shunt voltage, volts 2.453
Fcal at 40K shunt, lbs. 695.3
Zero voltage, volts -4.500
Full scale voltage, volts 5.500
Threshold voltage, mV 20


Load Cell data:
SN D14326; 1K-lb; HT SN #97223T
Calib 3.146 mv/v @ capy.
Shunt; X = 69.53%

I had to change values 2.453, 695.3, 1 of (1K), 3.146, and 69.53%.
It took me all freakin' day to do it - ridiculous but true.
0 Kudos
Message 5 of 7
(5,038 Views)
Are you using lv 7? If you are try using the build string express vi or the labview measurement file. They will help you do this.
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
0 Kudos
Message 6 of 7
(5,038 Views)
Hi,

I'm not sure with what you want it replaced. The attached Vi searches a
string and replaces it with another.

It uses the Match Pattern, so to find a double, use "[ +-][0-9]+\.[0-9]+" as
regular expression. This will find a space, plus or minus sign, one or more
numbers, a point, and one or more numbers. so it will find only doubles
(+12.123, 3.1, -4.1). Use "[ +-][0-9]+[\.\,][0-9]+" to catch commas as well.

You can adjust the VI to replace it with something you want. E.g. if you
want to replace the doubles with integers, get the 'match substring' output
inside the vi, convert it, and concatente instead of the 'Replace String'.

Use the VI twice to replace doubles and integers.

Good luck,

Wiebe.

"HTMike" wrote in message
news:506500000
008000000DCA30000-1042324653000@exchange.ni.com...
> Hello:
> I have been searching for vis that will search and replace double
> values in a text file. I have made my own that sort of works by taking
> a 1d array of strings I'm using for "keys" and an array of doubles
> that I want to substitute for the line with the key.
> There has GOT to be a packaged one but I can't find one that does all.
> Thanks



[Attachment Advanced String Replace.vi, see below]
0 Kudos
Message 7 of 7
(5,038 Views)