ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

replace string in a specific line

Solved!
Go to solution

Hi everyone thanks in advance for your time .

 

I'm almost finishing a project , (a software to handle hotel room reservation and a data base of passengers ) .

I made a function which writes to a .txt  file a cluster with a few string  fields of personal informacion , each field separated by tabs and each client separated by new line .

Example :          name      address    phone     etc.

                            Robert    xxxxxx         yyyyyyy     

                            Patrick    xxxxxx         yyyyyyy

                            Mila         xxxxxx         yyyyyyy

 

Now i don't know how can i do to search by name and to be able to modify each field .

Example :

                        if i search for Patrick , i want to be able to modify the address or phone number , or any  other field . 

 

I know how to search in a text file until i reach the word searched , but i don't figure out how to modify the field and write again the information to the same file in the same original line .

 

Any contribution will be great ! thanks again .

 

 

 

 

 

 

0 Kudos
Message 1 of 12
(5,695 Views)

Sounds like you may want to consider using a real database instead of a text file at some point.

For now, look into Search and Replace using Regular Expressions.

 

0 Kudos
Message 2 of 12
(5,688 Views)

Can you post at least the cluster control you are using, if not the VIs as well?

0 Kudos
Message 3 of 12
(5,681 Views)
You should be reading the file with the Read From Spreadsheet function. This gives you a 2D string array. It's easy to search and replace specific elements in the array. What is your problem with it?
0 Kudos
Message 4 of 12
(5,676 Views)

thank you all for helping me .

Here it is what i'm trying to do .

Download All
0 Kudos
Message 5 of 12
(5,665 Views)

Yep, doing a Read from Spreadsheet (or, in 2015, Read Delimited Spreadsheet) makes it relatively simple.  Row 1 has all the Headers, so you can find the Column headed "Name" by doing a search.  You can now search the Name Column looking for whomever, which gives you the Entry Row.  Finally, read the Row and do what you will.

 

Bob Schor

0 Kudos
Message 6 of 12
(5,660 Views)

thank you friend .

yes i don't have problems with search the line to modify , i have trouble with modify the field and then save the array to the original file , in a few words ,

i read the complete file and i get an array of strings , then i transform each element of that array into another array which contains each field of the desired line , now i perform the modifications to the fields , but then i have to save the modifications to the original file , (update the original file ) , i hope you could understand .

Thank you .

0 Kudos
Message 7 of 12
(5,651 Views)

Hi Maxi,

 

I think they are saying that if you use "read from spreadsheet" you will get a 2D array. You can easily replace your array element, then write to spreadsheet again. In this context a "spreadsheet" is just a delimited text file, it looks like you chose tabs so it should work quite nicely.

 

In short, don't use the read from text file, use the read from spreadsheet.

0 Kudos
Message 8 of 12
(5,645 Views)

thanks for your clear explanation , i did not understand sorry , i will try what you said .

Thank you very much , and thanks to all of you for always help !

0 Kudos
Message 9 of 12
(5,628 Views)

Sorry about being so dumb , but i can't achive what you suggested .

Here is the block diagram .

Thanks again for your kindness

 

 

0 Kudos
Message 10 of 12
(5,613 Views)