{"id":4620,"date":"2025-01-08T07:10:11","date_gmt":"2025-01-08T07:10:11","guid":{"rendered":"https:\/\/truelogic.org\/wordpress\/?p=4620"},"modified":"2025-01-08T07:13:02","modified_gmt":"2025-01-08T07:13:02","slug":"16-wxwidgets-wxarraystring","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2025\/01\/08\/16-wxwidgets-wxarraystring\/","title":{"rendered":"16.wxWidgets &#8211; wxArrayString"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>The wxArrayString is a class which acts as a wrapper for the standard vector class in C++. This enables us to create  a dynamic list of wxStrings and then do normal array operations with them. <\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<p>Given below is sample code which uses wxArrayString in three different ways.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n#include &lt;wx\/wx.h&gt;\n#endif \/\/ WX_PRECOMP\n#include &lt;wx\/string.h&gt;\n#include &lt;wx\/arrstr.h&gt;\n\nvoid printArr(wxArrayString* arr) {\n  for(size_t i=0; i &lt; arr-&gt;GetCount(); i++) {\n        wxString val = arr-&gt;Item(i);\n        wxPuts(val);\n    }\n}\n\nint main(int argc, char **argv) {\n    wxInitialize();\n    wxPuts(&quot;Starting..&quot;);\n\n    wxArrayString *arr1 = new wxArrayString();\n    arr1-&gt;Add(&quot;one&quot;); arr1-&gt;Add(&quot;two&quot;); arr1-&gt;Add(&quot;three&quot;);\n    wxString retVal = &quot;size of arr1=&quot; + wxString::Format(wxT(&quot;%zu&quot;), arr1-&gt;GetCount());\n    wxPuts(retVal);\n    printArr(arr1);\n    wxPuts(&quot;Sorting in ascending order&quot;);\n    arr1-&gt;Sort();\n    printArr(arr1);\n    arr1-&gt;Clear();\n    retVal = &quot;size of arr1 after clearing=&quot; + wxString::Format(wxT(&quot;%zu&quot;), arr1-&gt;GetCount());\n    wxPuts(retVal);\n\n    wxArrayString arr2;\n    arr2.Alloc(10);\n    for(size_t i=0; i &lt; 20; i++) {\n        wxString s = wxString::Format(wxT(&quot;%zu&quot;), i);\n        arr2.Add(s);\n    }\n    retVal = &quot;size of arr2 =&quot; + wxString::Format(wxT(&quot;%zu&quot;), arr2.GetCount());\n    printArr(&amp;arr2);\n    int searchElem = arr2.Index(wxT(&quot;3&quot;));\n    retVal = &quot;found &#039;3&#039; in element &quot; + wxString::Format(wxT(&quot;%d&quot;), searchElem);\n    wxPuts(retVal);\n    arr2.RemoveAt(searchElem);\n    searchElem = arr2.Index(wxT(&quot;3&quot;));\n    retVal = &quot;location of &#039;3&#039; after removal &quot; + wxString::Format(wxT(&quot;%d&quot;), searchElem);\n    wxPuts(retVal);\n    arr2.Shrink();\n\n    wxString test = wxT(&quot;one,two,three,four,five&quot;);\n    wxPuts(&quot;String values:&quot; + test);\n    wxArrayString arr3 = wxSplit(test, wxT(&#039;,&#039;));\n    printArr(&amp;arr3);\n\n    wxPuts(&quot;Ending..&quot;);\n\n    wxUninitialize();\n    return 1;\n}\n\n\n\n<\/pre><\/div>\n\n\n<p>The sample output is given below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"585\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2025\/01\/Screenshot-from-2025-01-08-12-39-30.png\" alt=\"\" class=\"wp-image-4625\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2025\/01\/Screenshot-from-2025-01-08-12-39-30.png 400w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2025\/01\/Screenshot-from-2025-01-08-12-39-30-300x439.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW The wxArrayString is a class which acts as a wrapper for the standard vector class in C++. This enables us to create a dynamic <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2025\/01\/08\/16-wxwidgets-wxarraystring\/\" title=\"16.wxWidgets &#8211; wxArrayString\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":4405,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,365],"tags":[],"class_list":["post-4620","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4620"}],"version-history":[{"count":5,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4620\/revisions"}],"predecessor-version":[{"id":4626,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4620\/revisions\/4626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/4405"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}