Logix 5000 pplit comma-separated String

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

Bit of a weird one here maybe. One thing that may be relevant(?) Doing this on a non-activated copy of RSLogix while waiting for the activation...
8
Replies
294
Views
Hello, I am trying to view the Module Properties for my IF8 and OF8 analog cards in RSLogix 5000 / Studio 5000. However, when I click on either...
6
Replies
398
Views
Hello everyone. I normally use ladder logic and am new to FBD logic. I am sure this is simple but for some reason I can not figure out how to...
17
Replies
767
Views
Good morning all. I have a question on how to convert the MULT function in Modicon to Logix 5000, due to how Modicon distributes the product. In...
2
Replies
311
Views
I am sure someone has maybe done this before. I have a FactoryTalk ME application on one VM, and my PLC program on a different VM. Is it...
5
Replies
447
Views
Top