From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scam string and replace value

Dear all,

 

I have one string that is read from Excel like this: "-90 db, 10 us, 100 Hz" that is used in some tests. I can't change this format.

The numbers can change and the code should be generic for any number.

For an expecific case I would like to replace the second number (duration in us) for a decimal that I will calculate.

This means that I only have to find the second "%d" (decimal number in the string) and replace for another number.

Is there any VI for that? I have been trying with some of them inside loops with no sucess... Please I would like some tips.

 

Thank you,

Thais Marques

0 Kudos
Message 1 of 15
(2,814 Views)

One of the many possible ways:

test.png

Hope this helps.


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 2 of 15
(2,796 Views)

Hi Thais

 

You can do something like this

 

1) Split string up in 3 bits by using the ,

2) Pull out what is between the 0 spaces og the middle string

3) Change this to a floating points tring with X number of precision

4) Build the string back up.

 

I have also attached the example in LabVIEW 2012 format.

SplitString.PNG

 

Best Regards

Anders Rohde

Applications Engineer

National Instruments Denmark

0 Kudos
Message 3 of 15
(2,791 Views)

Ugh, a pet peeve of mine.  You capitalize the "H" in "Hz" - why not the "B" in "dB?"  After all, they both refer to proper names.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 15
(2,786 Views)

@billko wrote:

Ugh, a pet peeve of mine.  You capitalize the "H" in "Hz" - why not the "B" in "dB?"  After all, they both refer to proper names.  😉


Unit capitalization is one of my peeves as well.  There's nothing quite like reading a test procedure and it says "Pulse the input for 500MS".  500 Megaseconds!????  Oh, you mean 500 milliseconds.  That's 500ms (or if you really want to capiltalize the seconds, 500mS).


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 5 of 15
(2,776 Views)

dear gosh people.
i just typed myself this. that is a simplification of my string (because the whole problem is much bigger!);

What is the problem of one letter not capitalized?!!!!!!!!!!!!!!!!!!!! that is not the point of my question.

that is not a document, is not a report............ just a post!!


anyway thanks for who helped me really 🙂

0 Kudos
Message 6 of 15
(2,769 Views)

 

Use the 'Spreadsheet String To Array' then 'Fract/Exp String To Number' to give you an array of floats from the Excel spread sheet.

You can then pick and choose which item you need or skip over or replace.

 

Scan string and replace value.png

 

I used a float because db and hz could be given as floating point

Omar
0 Kudos
Message 7 of 15
(2,747 Views)

Hi Omar,

 

is there a reason to use two functions when one will do the same?

check.png

Best regards,
GerdW


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

is there a reason to use two functions when one will do the same?

 

No. I first though the OP needed to replace a string keeping the output a string, So I started down that path keeping eveything as strings.

 

Then noticed their use of  ["%d" (decimal number in the string)] in their original post and at the last just added the extra convertions.

 

If all they wished to do is change the 10 us then the search and replace with regular expersion turned on will work.

Search and replace.png

 

Omar
0 Kudos
Message 9 of 15
(2,731 Views)

I just realized that is possible that not necessary the string that is been read will be given in "us" because allows that you type in "ms" also.

So here goes my not-so simple solution: (with B capitalized :P)

 

noise.png

0 Kudos
Message 10 of 15
(2,714 Views)