Dear folks,
I think I have a rather simple question but I could not find the right answer to my question:
I have made with Excel a CSV file where I would like to have some general data regarding my program variables.
I have made an program what let me read the file. The string I am currently get is at follows:
'IP_Adres;192.168.45.12$R$NPort_number;2000$R$NCycle_time;43$R$NStart_Standard_IO;20$R$N'
Now I want to split the string in multiple part, which I later would connect to the right variable.
By Google and experimenting I have reached to the following code for the first part of the splitting proces:
// Splitting the BOM of the string: Received_string := FileReadString; IF LEFT(STR:=New_string,3)= '' THEN Received_string_without_BOM :=RIGHT(STR:= Received_string,SIZE:= (LEN(STR:= Received_string))-3); END_IF //Splitting the remaining string in part for later declaration. WHILE index = 0 DO index_split_part := FIND(STR1:= Received_string_without_BOM,STR2:= '$R$N'); Part_of_String[index]:=LEFT(STR:=Received_string_without_BOM, SIZE:= index_split_part); index := index + 1; END_WHILE
However in the splitting proces I could not understand what is really happening. I understand that the Find() function returns the first value the $R$N in the Received_string_without_BOM.
Find()
This would mean that the index_split_part := 23
I|P| _ |A |d|r|e|s|;|1_|9 |2 |. |1 |6 |8 |. |4 |5 |. |1 |2 |$ |R |$ |N |P | 1|2| 3 |4 |5|6|7|0|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|
So the next part is to read the first 23 characters of the Received_string_without_BOM with the LEFT() function.
LEFT()
I expected that the outcome the following was: 'IP_Adres;192.168.45.12$'.
'IP_Adres;192.168.45.12$'
However the outcome is: 'IP_Adres;192.168.45.12$R'.
'IP_Adres;192.168.45.12$R'
I do not understand where the R after the $ sign comes from, because its place is 24 so it would not be added to the part_of the_string[index].
R
part_of the_string[index]
If I hard coded value 24 for the size it gives me the following return: 'IP_Adres;192.168.45.12$R$N'.
'IP_Adres;192.168.45.12$R$N'
I would expect everything till the R but the code adds the $N also to the string.
$N
I hope someone could explain to my what I am seeing wrong in my point of view?
With kind regards, George
the $N stands for newline and $R stands for line break. maybe these combinations are considered as 1 character/position? Not sure, just a thought...
see also: https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_operands_constant_string.html#:~:text=A%20string%20constant%20is%20a,belong%20to%20this%20character%20set.
Log in to post a comment.
Dear folks,
I think I have a rather simple question but I could not find the right answer to my question:
I have made with Excel a CSV file where I would like to have some general data regarding my program variables.
I have made an program what let me read the file. The string I am currently get is at follows:
Now I want to split the string in multiple part, which I later would connect to the right variable.
By Google and experimenting I have reached to the following code for the first part of the splitting proces:
However in the splitting proces I could not understand what is really happening.
I understand that the
Find()
function returns the first value the $R$N in the Received_string_without_BOM.This would mean that the index_split_part := 23
So the next part is to read the first 23 characters of the Received_string_without_BOM with the
LEFT()
function.I expected that the outcome the following was:
'IP_Adres;192.168.45.12$'
.However the outcome is:
'IP_Adres;192.168.45.12$R'
.I do not understand where the
R
after the $ sign comes from, because its place is 24 so it would not be added to thepart_of the_string[index]
.If I hard coded value 24 for the size it gives me the following return:
'IP_Adres;192.168.45.12$R$N'
.I would expect everything till the
R
but the code adds the$N
also to the string.I hope someone could explain to my what I am seeing wrong in my point of view?
With kind regards,
George
Last edit: george32 2024-09-27
the $N stands for newline and $R stands for line break. maybe these combinations are considered as 1 character/position? Not sure, just a thought...
see also: https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_operands_constant_string.html#:~:text=A%20string%20constant%20is%20a,belong%20to%20this%20character%20set.