LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Convert Different String Formats into a Common Array in LabVIEW..?

 

 

Hi everyone,

I am working on a LabVIEW application where I receive product information as a string and need to convert it into an array using a common logic.

I have two different input string formats.

String 1:

Product\sName\s\s:\sROSUVASTATIN\sCALCIUM\sBP/IP\sProduct\sCode\s:\sRSC\sBatch\sNo\s:\sRSC26022\sMfg\sDate\s:\sAPR-2026\sRetest\sDate\s:\sMAR-2030\sDRUM\sNO.\s:\s01\sOF\s09\sTare\sWeight:\s3.43\sNet\sWeight\s:\s25.00\sGross\sWeight\s:\s28.43\sBatch\sSize\s:208.00\sKgs\sStorage\sCondition\s:STORE\sIN\sWELL\sCLOSED\sCONTAINERS

String 2:

Product\sName:\sPREGABALIN\sIP\nProduct\sCode:\sPRG\nBatch\sNo:PRG26229\nMfg.\sDate:\sMAR-2026\nExpiry\sDate:\sFEB-2031\nDRUM\sNO:\s02\sOF\s08\nGross\sWeight:29.00\nTare\sWeight:\s4.00\nNet\sWeight\s:\s29.00\nBatch\sSize\s:1000.00\sKgs\nStorage\sCondition:\sSTORE\sIN\sWELL\sCLOSED\sCONTAINERS

The string indicator is set to Display Codes, so \s represents spaces and \n represents new-line characters.

My requirement is to create a common logic that can handle both formats and convert the data into an array, for example:

Product Name       → PREGABALIN IP
Product Code       → PRG
Batch No           → PRG26229
Mfg. Date          → MAR-2026
Expiry Date        → FEB-2031
DRUM NO             → 02 OF 08
Gross Weight       → 29.00
Tare Weight        → 4.00
Net Weight         → 29.00
Batch Size         → 1000.00 Kgs
Storage Condition  → STORE IN WELL CLOSED CONTAINERS

I initially considered using Spreadsheet String to Array, but the two input formats are not identical. In particular, String 1 does not contain \n between every field, while String 2 does.

What would be the best way to design a robust common parsing logic in LabVIEW that can handle both formats?

Should I normalize the whitespace/newline characters first and then split the string based on the field names or :?

 

Any suggestions or recommended LabVIEW functions/architecture would be appreciated.

 

Thanks!

0 Kudos
Message 1 of 6
(749 Views)

Hi Tusharvp,

 


@Tusharvp4 wrote:

I initially considered using Spreadsheet String to Array, but the two input formats are not identical. In particular, String 1 does not contain \n between every field, while String 2 does.

What would be the best way to design a robust common parsing logic in LabVIEW that can handle both formats?

Should I normalize the whitespace/newline characters first and then split the string based on the field names or :?

 

Any suggestions or recommended LabVIEW functions/architecture would be appreciated.


  • String2 is "nice" as you can easily separate by linebreaks.
  • String1 is "bad" as there are only spaces to separate words: you NEED to know the identifier and to detect the corresponding value.
  • I suggest to check for linebreaks, then call two different subVI to parse the "nice" and "bad" strings differently…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(734 Views)

String 2 is simple, just do a Spreadsheet string to array on "\n" and then run the resulting array through a loop and cut at ":" and you'll have a nice 2D array.

The 1st one is kind of horrible. If you know you always have those titles You can do a text search and replace for e.g. Product Text and replace it with \nProduct Text, then you should be able to reuse the previous solution.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 6
(652 Views)

A "common logic" would be difficult, but you can easily check for the presence of \n and switch algorithms accordingly. As you said, String #2 is trivial:

 

altenbach_0-1791295009745.png

 

For string #1, it helps to know details of the pattern. For example is the ID always exactly two words followed by a ":" as seen here? If not, is there a comprehensive list of all possible IDs?

 

Message 4 of 6
(623 Views)

@altenbach wrote:

For string #1, it helps to know details of the pattern. For example is the ID always exactly two words followed by a ":" as seen here?

 


If the tag is always two words, here's a possible solution. I am sure it can be simplified significantly.

 

altenbach_0-1791304190645.png

 

Message 5 of 6
(597 Views)

The issue with string 1 is that there's no way to know when the "value" for one item ends and the "label" for the next one begins. So you'll want to add them to a list, then use that list with Scan String for Tokens.

 

BertMcMahan_0-1791308963187.png

 

However, since string 1 and 2 don't have the same labels for all items, you'll want to sanitize the inputs (for example, "Mfg Date" vs "Mfg. Date"). You could include both versions in the Fields list, but this way all of your outputs have the same field label.

 

This also works with non-listed field names from String 2 by adding the newline as a delimiter. 

 

Results with string 1:

BertMcMahan_1-1791309154255.png

 

Results with string 2:

BertMcMahan_0-1791309135043.png

 

Message 6 of 6
(588 Views)