LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to separate words and numbers in a string?

Solved!
Go to solution

Hello everyone,
I’d like to know if it’s possible to separate words from numbers in a string.
For example, my string is: "CH0: float, CH1: float, CH2: float". I’d like to extract the float values in order to plot them in different charts.
Thanks in advance to anyone who takes the time to look into this !

 

To provide more context, my VI acts as a TCP server that reads messages sent by the client, which are of the format described above.

0 Kudos
Message 1 of 4
(146 Views)
Solution
Accepted by Ouinon

Hi Quinon,

 


@Ouinon wrote:

I’d like to know if it’s possible to separate words from numbers in a string.
For example, my string is: "CH0: float, CH1: float, CH2: float". I’d like to extract the float values in order to plot them in different charts.


Yes, it's possible.

 

  1. Use SpreadsheetStringToArray with "," (comma) as separator to change the string into an array of strings.
  2. Parse each string element with ScanFromString and the format string "CH%d: %f" to get the channel number and the float value.

What have you tried and where are you stuck?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(132 Views)
Solution
Accepted by Ouinon

@Ouinon wrote:

For example, my string is: "CH0: float, CH1: float, CH2: float".


the only "numeric" in your example string are 0, 1, and 2.

 

If the "float" in you string are numbers, and the "trimmings" are always the same, all you needs is the following:

 

altenbach_1-1747841701905.png

 

 

 

0 Kudos
Message 3 of 4
(68 Views)

Thank you !

 

Your solution is simple so perfect for me 🙂

0 Kudos
Message 4 of 4
(17 Views)