{"id":1074,"date":"2025-02-05T19:59:52","date_gmt":"2025-02-05T19:59:52","guid":{"rendered":"https:\/\/monkey.ploogie.co.uk\/?page_id=1074"},"modified":"2025-02-05T19:59:53","modified_gmt":"2025-02-05T19:59:53","slug":"mwnci-cargs-function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-cargs-function\/","title":{"rendered":"Mwnci cargs() Function"},"content":{"rendered":"<h2>Syntax<\/h2>\n<p>cargs<strong>(<em>string<\/em>)<\/strong><\/p>\n<h2>Description<\/h2>\n<p>The <i>cargs()<\/i> function returns an array of arguments from a given string that can be handled in a similar way as the results of the args() function.<\/p>\n<h2>Example<\/h2>\n<pre>\r\nnewArgs=cargs(\"-f \/bin\/ls -title \"This is a string\" -foo -b 9\")\r\nprintln(newArgs)\r\n\r\n\r\n[\"-f\", \"\/bin\/ls\", \"-title\", \"\\\"This is a string\\\"\", \"-foo\", \"-b\", \"9\"]\r\n<\/pre>\n<p>This may come in handy for passing multiple arguments to functions. <\/p>\n<pre>\r\nfunction foo(FArgs) {\r\n    a=10\r\n    b=5\r\n    Args=cargs(FArgs)\r\n    if (Args[0] == \"-b\") {\r\n        b=int(Args[1])\r\n    }\r\n    return a + b\r\n}\r\nz=foo(\"-b 6\")\r\nprintln(z)\r\nz=foo(\"\")\r\nprintln(z)\r\n\r\n16\r\n15\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Syntax cargs(string) Description The cargs() function returns an array of arguments from a given string that can be handled in a similar way as the results of the args() function. Example newArgs=cargs(&#8220;-f \/bin\/ls -title &#8220;This is a string&#8221; -foo -b 9&#8243;) println(newArgs) [&#8220;-f&#8221;, &#8220;\/bin\/ls&#8221;, &#8220;-title&#8221;, &#8220;\\&#8221;This is a string\\&#8221;&#8221;, &#8220;-foo&#8221;, &#8220;-b&#8221;, &#8220;9&#8221;] This may come &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-cargs-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci cargs() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1074","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1074"}],"version-history":[{"count":3,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1074\/revisions"}],"predecessor-version":[{"id":1077,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1074\/revisions\/1077"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}