Logix 5000 pplit comma-separated String

VulcPAC

Member
Join Date
Oct 2018
Location
Mallorca
Posts
21
Hi to all:

I have to split a comma separated string into respective strings, but with the results in literal strings.
I made the logic with a FOR DO cycle, reading the string char by char, then using DTOS instruction to save every char (STRING Type) and then concatenating that char when is not a comma. With this algorithm I can split the string, the problem is that the results are in numerical ASCII, not literal.

Base string to split is a STRING Type (Len and Data)
Result String is an STRING array, with every splitted string stored in each element

For example if my string is AB,CD,FG I need to obtain a String array like this:

String_Array[0]='AB'
String_Array[1]='CD'
String_Array[2]='FG'

Now, I am obtaining this

String_Array[0]='6566'
String_Array[1]='6768'
String_Array[2]='6970'

Anything that I'm doing wrong or missing?
Any help is welcome.

Thanks and nice day for all!
 
Instead of using DTOS to move from the source to result strings, just move the individual characters (SINTs). For example, "MOV Source.DATA[3] String_Array[1].DATA[0]" to move the fourth character from the source string to the first character of your second result array.
 
I should also add that if you "manually" construct a string this way (as opposed to using ASCII instructions), it is good practice to increment the .LEN element of the structure as characters are added to the .DATA array.
 
Instead of using DTOS to move from the source to result strings, just move the individual characters (SINTs). For example, "MOV Source.DATA[3] String_Array[1].DATA[0]" to move the fourth character from the source string to the first character of your second result array.


Mispeld:

The problem with this is that I'm using CONCAT instruction to concatenate chars in each array element. For example for String_Array[0]='AB' I concatenate char A with char B to construct the string. CONCAT only allows strings, so I use DTOS to obtain ASCII because I can't use SINT data in CONCAT instruction

Thanks!
 
I don't know if this applies to your situation or not, but I just had a project where I had to convert from ASCII to strings because of an incompatibility between PanelBuilder 32 and FactoryTalk View Studio ME. The easiest solution for me was to swap the bytes in the ASCII tags, copy them into a string, and set the length of the string to 10. All of our labels are 10 characters long, regardless of the data, so this made the conversion a little easier.

ASCII to String.JPG
 
Mispeld:

The problem with this is that I'm using CONCAT instruction to concatenate chars in each array element. For example for String_Array[0]='AB' I concatenate char A with char B to construct the string. CONCAT only allows strings, so I use DTOS to obtain ASCII because I can't use SINT data in CONCAT instruction

Thanks!

In order to use CONCAT in this example, you will need to create a one-character string to temporarily hold the individual characters being moved from the source string to your array of parsed strings. Let's say this Temp_String is defined as a standard STRING type. Set Temp_String.LEN equal to 1. Then move the each source character into Temp_String using "MOV Source.DATA[x] Temp_String.DATA[0]" and then concatenate Temp_String onto your String_Array element after each MOV from the source. This has the advantage of correctly managing the Length of your result arrays.
 
I had written one a while back using FIND, MID, and DELETE functions.

Find a comma, copy characters up to the comma, lop off the front characters, then do it again. I'll see if I can find it... or write one up quickly if I can't...
 
Hi:

Finally I solved with other algorithm, using MID instruction. I created a DINT array and searched the String for every comma, storing each position in the array. For example for AB,CD,EF,GH my Position_Array is 3, 6 and 9

Then, with a FOR DO cycle, using MID instruction, I extracted the strings between the comma's positions (values stored in the previous array), using as Start the n element of the array and for Qty, the n+1 element of the array.

Thanks to all for your answers.
 

Similar Topics

Hi folks, in the alarm manager of Rslogix 5000, the tag-based alarm has been created. But when I tried to change the condition, it was found the...
Replies
2
Views
142
I am completely stuck on building a ladder program that requires a start button to be pressed 3 times to turn on motor 1. Then motor 2 starts...
Replies
20
Views
569
Is there a way to use the FAL instruction to do +=2 instead of +=1? I have an array that is organized with alternating "data" and "flag" values...
Replies
5
Views
125
I have an AOI with revision notes. Someone entered the last note into the description instead of the notes. I cannot just click into the revision...
Replies
4
Views
148
Back
Top Bottom