{"id":14727,"date":"2024-06-02T20:49:47","date_gmt":"2024-06-02T17:49:47","guid":{"rendered":"https:\/\/elzero.org\/?p=14727"},"modified":"2024-06-02T20:50:41","modified_gmt":"2024-06-02T17:50:41","slug":"implement-functions-with-cpp-string-slice","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/implement-functions-with-cpp-string-slice\/","title":{"rendered":"String Slice"},"content":{"rendered":"<h3>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-c\">\r\n#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\n\/*\r\n  String Slice\r\n  \"Hello, World\" -> \"Hello\"\r\n*\/\r\n\r\nstring slice(string st, int start, int end, int step = 1, bool rev = false)\r\n{\r\n  string result;\r\n  for (int i = start; i < end; i += step)\r\n  {\r\n    if (rev)\r\n    {\r\n      result = st[i] + result; \/\/ Result = l + l + e + H + \"\"\r\n      \/\/ [Loop 1] -> H + \"\"\r\n      \/\/ [Loop 2] -> e + H + \"\"\r\n      \/\/ [Loop 3] -> l + e + H + \"\"\r\n      \/\/ [Loop 4] -> l + l + e + H + \"\"\r\n      \/\/ [Loop 5] -> olleH\r\n    }\r\n    else\r\n    {\r\n      result += st[i];\r\n    }\r\n  }\r\n  return result;\r\n}\r\n\r\nint main()\r\n{\r\n  cout << slice(\"Hello, World\", 0, 5) << endl;          \/\/ Hello\r\n  cout << slice(\"Hello, World\", 0, 6) << endl;          \/\/ Hello,\r\n  cout << slice(\"Hello, World\", 0, 5, 2) << endl;       \/\/ Hlo\r\n  cout << slice(\"Hello, World\", 0, 5, 1, true) << endl; \/\/ olleH\r\n  return 0;\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1454],"tags":[],"class_list":["post-14727","post","type-post","status-publish","format-standard","hentry","category-implement-functions-with-cpp"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=14727"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14727\/revisions"}],"predecessor-version":[{"id":14729,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14727\/revisions\/14729"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=14727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=14727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=14727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}