<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to CSV file and string manipulation.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/98e94beeed/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/98e94beeed/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/98e94beeed/</id><updated>2024-09-27T19:56:43.493000Z</updated><subtitle>Recent posts to CSV file and string manipulation.</subtitle><entry><title>CSV file and string manipulation.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/98e94beeed/?limit=25#1c37" rel="alternate"/><published>2024-09-27T19:56:43.493000Z</published><updated>2024-09-27T19:56:43.493000Z</updated><author><name>rmaas</name><uri>https://forge.codesys.com/u/rmaas/</uri></author><id>https://forge.codesys.comf0ce2f02d87833474d52722ecd37cdf10a77ad07</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;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...&lt;/p&gt;
&lt;p&gt;see also: &lt;a href="https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_operands_constant_string.html#:~:text=A%20string%20constant%20is%20a" rel="nofollow"&gt;https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_operands_constant_string.html#:~:text=A%20string%20constant%20is%20a&lt;/a&gt;,belong%20to%20this%20character%20set.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>CSV file and string manipulation.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/98e94beeed/?limit=25#c423" rel="alternate"/><published>2024-09-27T14:00:25.554000Z</published><updated>2024-09-27T14:00:25.554000Z</updated><author><name>george32</name><uri>https://forge.codesys.com/u/george32/</uri></author><id>https://forge.codesys.com06f3f4661e9d4ee630fad6f3cbde4b990cd95f4b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Dear folks,&lt;/p&gt;
&lt;p&gt;I think I have a rather simple question but I could not find the right answer to my question:&lt;/p&gt;
&lt;p&gt;I have made with Excel a CSV file where I would like to have some general data regarding my program variables.&lt;/p&gt;
&lt;p&gt;I have made an program what let me read the file. The string I am currently get is at follows:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;'ï»¿IP_Adres;192.168.45.12$R$NPort_number;2000$R$NCycle_time;43$R$NStart_Standard_IO;20$R$N'&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now I want to split the string in multiple part, which I later would connect to the right variable.&lt;/p&gt;
&lt;p&gt;By Google and experimenting I have reached to the following code for the first part of the splitting proces:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Splitting&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;BOM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;string&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;Received_string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;FileReadString&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;IF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;LEFT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;STR&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;New_string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'ï»¿'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;THEN&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Received_string_without_BOM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;RIGHT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;STR&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Received_string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="k"&gt;SIZE&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;LEN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;STR&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Received_string&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;END_IF&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;Splitting&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;remaining&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;later&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;declaration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="k"&gt;WHILE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;index&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;DO&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;index_split_part&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;FIND&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;STR1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Received_string_without_BOM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;STR2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'$R$N'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Part_of_String&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;LEFT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;STR&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Received_string_without_BOM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;SIZE&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;index_split_part&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;index&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;index&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_WHILE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However in the splitting proces I could not understand what is really happening. &lt;br/&gt;
 I understand that the &lt;strong&gt;&lt;code&gt;Find()&lt;/code&gt;&lt;/strong&gt; function returns the first value the $R$N in the Received_string_without_BOM.&lt;/p&gt;
&lt;p&gt;This would mean that the index_split_part := 23 &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;I|P| &lt;span class="ge"&gt;_ |A |d|r|e|s|;|1_&lt;/span&gt;|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|
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So the next part is to read the first 23 characters of the Received_string_without_BOM with the &lt;strong&gt;&lt;code&gt;LEFT()&lt;/code&gt;&lt;/strong&gt; function.&lt;/p&gt;
&lt;p&gt;I expected that the outcome the following was: &lt;strong&gt;&lt;code&gt;'IP_Adres;192.168.45.12$'&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;However the outcome is: &lt;strong&gt;&lt;code&gt;'IP_Adres;192.168.45.12$R'&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I do not understand where the &lt;strong&gt;&lt;code&gt;R&lt;/code&gt;&lt;/strong&gt; after the $ sign comes from, because its place is 24 so it would not be added to the &lt;strong&gt;&lt;code&gt;part_of the_string[index]&lt;/code&gt;&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;If I hard coded value 24 for the size it gives me the following return:&lt;br/&gt;
&lt;strong&gt;&lt;code&gt;'IP_Adres;192.168.45.12$R$N'&lt;/code&gt;&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;I would expect everything till the &lt;code&gt;**R**&lt;/code&gt; but the code adds the &lt;strong&gt;&lt;code&gt;$N&lt;/code&gt;&lt;/strong&gt; also to the string.&lt;/p&gt;
&lt;p&gt;I hope someone could explain to my what I am seeing wrong in my point of view?&lt;/p&gt;
&lt;p&gt;With kind regards,&lt;br/&gt;
George&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>