10-05-2026 12:26 PM
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!
10-05-2026 01:00 PM
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
\nbetween 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.
10-06-2026 06:24 AM
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.
10-06-2026 09:01 AM
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:
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?
10-06-2026 11:31 AM
@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.
10-06-2026 12:51 PM - edited 10-06-2026 12:52 PM
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.
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:
Results with string 2: