{"id":915,"date":"2013-11-08T12:29:38","date_gmt":"2013-11-08T12:29:38","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=915"},"modified":"2022-02-17T06:24:03","modified_gmt":"2022-02-17T06:24:03","slug":"convert-pasted-list-into-array-of-strings","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/strings\/useful-string-examples\/convert-pasted-list-into-array-of-strings","title":{"rendered":"Convert Pasted List Into Array Of Strings"},"content":{"rendered":"<p>\n&nbsp;\n<\/p>\n<pre>\r\n<code>\r\n\r\n\tarray&lt;String^&gt; ^NewUsernames = NewUsernames = gcnew array&lt;String^&gt;(0);\r\n\r\n\tString ^sPastedString;\r\n\tString ^sName;\r\n\tString ^sMarker = &quot;[MARKERdfghj23l]&quot;;\r\n\tint Count;\r\n\r\n\ttry\r\n\t{\r\n\t\t\r\n\t\tsPastedString = txtPasteUsernames-&gt;Text;\r\n\t\ttxtPasteUsernames-&gt;Text = &quot;&quot;;\r\n\t\tsPastedString = sPastedString-&gt;Trim();\r\n\r\n\t\tif (sPastedString-&gt;Length &lt;= 1)\t\t\/\/Ignore single character in case user tries to type into box\r\n\t\t\treturn;\r\n\r\n\t\t\/\/Place markers between each name\r\n\t\tsPastedString = sPastedString-&gt;Replace(&quot;\\r\\n&quot;, sMarker);\r\n\t\tsPastedString = sPastedString-&gt;Replace(&quot;\\n&quot;, sMarker);\r\n\t\tsPastedString = sPastedString-&gt;Replace(&quot;\\r&quot;, sMarker);\r\n\t\tsPastedString = sPastedString-&gt;Replace(&quot;,&quot;, sMarker);\r\n\t\tsPastedString = sPastedString-&gt;Replace(&quot;\\t&quot;, sMarker);\r\n\t\tsPastedString += &quot;[MARKERdfghj23l]&quot;;\r\n\r\n\t\t\/\/Get each name\r\n\t\twhile (sPastedString-&gt;LastIndexOf(sMarker) &gt; 0)\r\n\t\t{\r\n\t\t\tsName = sPastedString-&gt;Substring(0, (sPastedString-&gt;IndexOf(sMarker)));\r\n\t\t\tsPastedString = sPastedString-&gt;Substring(sName-&gt;Length + sMarker-&gt;Length);\r\n\r\n\t\t\tsName = sName-&gt;Trim();\r\n\t\t\tif (sName-&gt;Length &gt; 0)\r\n\t\t\t{\r\n\t\t\t\t\/\/Check name has not already been added\r\n\t\t\t\tfor (Count = 0; Count &lt; NewUsernames-&gt;Length; Count++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (NewUsernames[Count] == sName)\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\tif (Count == NewUsernames-&gt;Length)\r\n\t\t\t\t{\r\n\t\t\t\t\t\/\/Add it to the array\r\n\t\t\t\t\tArray::Resize(NewUsernames, NewUsernames-&gt;Length + 1);\r\n\t\t\t\t\tNewUsernames[(NewUsernames->Length - 1)] = sName;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t\/\/----- DISPLAY THE ARRAY OF USERNAMES -----\r\n\t\ttxtUsernamesToAdd-&gt;Text = &quot;&quot;;\r\n\t\tfor (Count = 0; Count &lt; NewUsernames-&gt;Length; Count++)\r\n\t\t{\r\n\t\t\ttxtUsernamesToAdd-&gt;Text += NewUsernames[Count] + &quot;\\r\\n&quot;;\r\n\t\t}\r\n\t}\r\n\tcatch (Exception ^e)\r\n\t{\r\n\t\tGlobalObjects::EventLog1-&gt;AddEvent(true, 0x00, Convert::ToString(e));\r\n\t}\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; array&lt;String^&gt; ^NewUsernames = NewUsernames = gcnew array&lt;String^&gt;(0); String ^sPastedString; String ^sName; String ^sMarker = &quot;[MARKERdfghj23l]&quot;; int Count; try { sPastedString = txtPasteUsernames-&gt;Text; txtPasteUsernames-&gt;Text = &quot;&quot;; sPastedString = sPastedString-&gt;Trim(); if (sPastedString-&gt;Length &lt;= 1) \/\/Ignore single character in case user tries to type into box return; \/\/Place markers between each name sPastedString = sPastedString-&gt;Replace(&quot;\\r\\n&quot;, sMarker); sPastedString [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[95],"tags":[],"class_list":["post-915","post","type-post","status-publish","format-standard","hentry","category-useful-string-examples"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=915"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/915\/revisions"}],"predecessor-version":[{"id":917,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/915\/revisions\/917"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}