<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to replace / insert character into double quote of a string in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562261#M77533</link>
    <description>&lt;P&gt;If you know the starting tag (in this case, "ak:Unit"), then you can use &lt;CODE class=" language-jsl"&gt;Parse XML()&lt;/CODE&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
ex = "\[&amp;lt;ak:Unit X="0" Y="1" Id="U33"&amp;gt;]\";
Parse XML( ex,
	On Element( "ak:Unit", Start Tag( xml = XML Attr() ) ),
);
xml &amp;lt;&amp;lt; Remove( "" );

default 1 = "new X";
default 2 = "new Y";
default 3 = "new Id";

new vals = [=&amp;gt;];
new vals["X"] = default 1;
new vals["Y"] = default 2;
new vals["Id"] = default 3;

new string = "&amp;lt;ak:Unit";
keys = {"X", "Y", "Id"};
For( i = 1, i &amp;lt;= 3, i++,
	new string ||= " " || keys[i] || "=\!"" || new vals[keys[i]] || "\!""
);
new string ||= "&amp;gt;";
Write( new string )&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 30 Oct 2022 22:10:42 GMT</pubDate>
    <dc:creator>ErraticAttack</dc:creator>
    <dc:date>2022-10-30T22:10:42Z</dc:date>
    <item>
      <title>how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562130#M77513</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string like this .&lt;/P&gt;&lt;P&gt;&amp;lt;ak:Unit X="0" Y="1" Id="U33"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know how to replace characters in double quotes of a string&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;ak:Unit X="&lt;FONT color="#FF0000"&gt;0&lt;/FONT&gt;" Y="&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;" Id="&lt;FONT color="#FF0000"&gt;U33&lt;/FONT&gt;"&amp;gt;&amp;nbsp; ==&amp;gt;&amp;nbsp;&amp;lt;ak:Unit X="&lt;FONT color="#FF0000"&gt;Default1&lt;/FONT&gt;" Y="&lt;FONT color="#FF0000"&gt;Default2&lt;/FONT&gt;" Id="&lt;FONT color="#FF0000"&gt;Default3&lt;/FONT&gt;"&amp;gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:01:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562130#M77513</guid>
      <dc:creator>PhamBao</dc:creator>
      <dc:date>2023-06-09T16:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562133#M77514</link>
      <description>&lt;P&gt;Substitute (or substitute into) is one option. Just remember to use escape character for double quote.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

str = "\[&amp;lt;ak:Unit X="0" Y="1" Id="U33"&amp;gt;]\";

result = "\[&amp;lt;ak:Unit X="Default1" Y="Default2" Id="Default3"&amp;gt;]\";

new_str = Substitute(str, "\!"0\!"", "\!"Default1\!"", "\!"1\!"", "\!"Default2\!"", "\!"U33\!"", "\!"Default3\!"");

result == new_str;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Oct 2022 06:46:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562133#M77514</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-10-29T06:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562136#M77515</link>
      <description>&lt;P&gt;Given the specifics of the example string&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;lt;ak:Unit X="0" Y="1" Id="U33"&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The actual substitute() function can be simplified to&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Substitute(str, "0", "Default1", "1", "Default2", "U33", "Default3");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 08:58:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562136#M77515</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-10-29T08:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562185#M77524</link>
      <description>&lt;P&gt;Hi Jthi,&lt;BR /&gt;It works!&lt;BR /&gt;Same question, but this time how could I substitute characters in a string by variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;BR /&gt;Default1, Default2 and Default3 are now variables and their value would be changed&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;result = "\[&amp;lt;ak:Unit X="Default1" Y="Default2" Id="Default3"&amp;gt;]\";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 15:52:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562185#M77524</guid>
      <dc:creator>PhamBao</dc:creator>
      <dc:date>2022-10-29T15:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562194#M77525</link>
      <description>&lt;P&gt;Got it ! thank you a lot&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 15:55:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562194#M77525</guid>
      <dc:creator>PhamBao</dc:creator>
      <dc:date>2022-10-29T15:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562195#M77526</link>
      <description>&lt;P&gt;Here is an example where the first element is replaced from a variables value&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

str = "\[&amp;lt;ak:Unit X="__one__" Y="1" Id="U33"&amp;gt;]\";

sub1 = "theSub1";

mySub = Substitute(str,expr(__one__), sub1, "Default2", "U33", "Default3");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Oct 2022 16:01:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562195#M77526</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-10-29T16:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562200#M77527</link>
      <description>&lt;P&gt;I think fairly rarely you would first add variable names to the string and then start replacing those with the values, but you could do it with Eval Insert.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better option would be to directly add those values there. Example below has both options, first adds ¤Default1¤ and so on and replaces those by using Eval Insert Into (see scripting index), next one is using Associative array. Associative array is using the strings which are to be replaced as keys and values are the new values (I would use second option).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

str = "\[&amp;lt;ak:Unit X="0" Y="1" Id="U33"&amp;gt;]\";

new_str = Substitute(str, "\!"0\!"", "\!"¤Default1¤\!"", "\!"1\!"", "\!"¤Default2¤\!"", "\!"U33\!"", "\!"¤Default3¤\!"");

Default1 = "test1";
Default2 = "test2";
Default3 = "test3";

Write("Eval Insert into: \!N");
Eval Insert Into(new_str, "¤");
Write(new_str);

Write("\!N\!NAssociative Array:\!N");
aa_replace = Associative Array();
aa_replace["\!"0\!""] = "\!"test1\!"";
aa_replace["\!"1\!""] = "\!"test2\!"";
aa_replace["\!"U33\!""] = "\!"test3\!"";

new_str2 = Substitute(str, aa_replace &amp;lt;&amp;lt; get keys, aa_replace &amp;lt;&amp;lt; get values);
write(new_str2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Oct 2022 17:21:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562200#M77527</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-10-29T17:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace / insert character into double quote of a string</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562261#M77533</link>
      <description>&lt;P&gt;If you know the starting tag (in this case, "ak:Unit"), then you can use &lt;CODE class=" language-jsl"&gt;Parse XML()&lt;/CODE&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
ex = "\[&amp;lt;ak:Unit X="0" Y="1" Id="U33"&amp;gt;]\";
Parse XML( ex,
	On Element( "ak:Unit", Start Tag( xml = XML Attr() ) ),
);
xml &amp;lt;&amp;lt; Remove( "" );

default 1 = "new X";
default 2 = "new Y";
default 3 = "new Id";

new vals = [=&amp;gt;];
new vals["X"] = default 1;
new vals["Y"] = default 2;
new vals["Id"] = default 3;

new string = "&amp;lt;ak:Unit";
keys = {"X", "Y", "Id"};
For( i = 1, i &amp;lt;= 3, i++,
	new string ||= " " || keys[i] || "=\!"" || new vals[keys[i]] || "\!""
);
new string ||= "&amp;gt;";
Write( new string )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Oct 2022 22:10:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-replace-insert-character-into-double-quote-of-a-string/m-p/562261#M77533</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-10-30T22:10:42Z</dc:date>
    </item>
  </channel>
</rss>

