{"id":378,"date":"2026-03-24T14:10:17","date_gmt":"2026-03-24T06:10:17","guid":{"rendered":"https:\/\/jiangqvweihuan.cn\/?p=378"},"modified":"2026-04-25T12:43:24","modified_gmt":"2026-04-25T04:43:24","slug":"string%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/jiangqvweihuan.cn\/index.php\/2026\/03\/24\/string%e7%b1%bb\/","title":{"rendered":"\u6784\u7b97\u6cd5\u5ea6\u00b7string\u7c7b"},"content":{"rendered":"\n<p>\u76f8\u4fe1\u5927\u5bb6\u5bf9\u4e8estring\u7684\u57fa\u7840\u4f7f\u7528\u5927\u62b5\u90fd\u5df2\u7ecf\u7089\u706b\u7eaf\u9752\uff0c\u6b64\u7bc7\u6587\u7ae0\u4ec5\u4ec5\u4f5c\u4e3a\u8865\u5145\u4e00\u4e9b\u6211\u7ecf\u5e38\u9700\u8981\u8bb0\u5fc6\u6216\u8005\u89c9\u5f97\u6709\u7528\u7684\u70b9\u4ee5\u53ca\u4e00\u4e9b\u5bf9\u4e8e\u5b57\u7b26\u4e32\u5904\u7406\u7684\u4e00\u4e9b\u6280\u5de7\u548c\u77e5\u8bc6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001string\u5e38\u7528\u51fd\u6570<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>size()\u548clength()\uff1a\u8fd4\u56destring\u5bf9\u8c61\u7684\u5b57\u7b26\u4e2a\u6570\uff0c\u4ed6\u4eec\u6267\u884c\u6548\u679c\u76f8\u540c\uff0c\u4e2a\u4eba\u503e\u5411\u524d\u8005\u3002<\/li>\n\n\n\n<li>push_back() \u548c insert()\uff1a\u524d\u8005\u5c3e\u63d2\uff0c\u540e\u8005\u4efb\u610f\u4f4d\u7f6e\u63d2\u5165\u3002<\/li>\n\n\n\n<li>append()\uff1a\u5b57\u7b26\u4e32\u62fc\u63a5\u3002<\/li>\n\n\n\n<li>tolower()\u548ctoupper()\uff1a\u524d\u8005\u5bf9\u5b57\u6bcd\u53d8\u4e3a\u5c0f\u5199\uff0c\u540e\u8005\u5927\u5199\u3002<\/li>\n\n\n\n<li>find()\uff1a\u67e5\u627e\u5bf9\u5e94\u7684\u5b50\u4e32\uff0c\u8fd4\u56de\u9996\u5b57\u6bcd\u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u4e0b\u6807\u3002<\/li>\n\n\n\n<li>substr()\uff1a\u622a\u53d6\u5b57\u7b26\u4e32\u7684\u5b57\u4e32\u3002<\/li>\n\n\n\n<li>erase()\uff1a\u5220\u9664\u5b57\u7b26\u4e32\u533a\u95f4\u3002<\/li>\n\n\n\n<li>reverse()\uff1a\u7ffb\u8f6c\u5bf9\u5e94\u533a\u95f4\u7684\u6240\u6709\u5b57\u7b26\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nsigned main()\n{\n    string s(5, 'a');\n    cout &lt;&lt; \"\u521d\u59cb\u5b57\u7b26\u4e32\u662f:\";\n    cout &lt;&lt; s &lt;&lt; endl;\n    cout &lt;&lt; \"\u5b57\u7b26\u4e32s\u7684\u957f\u5ea6:\";\n    cout &lt;&lt; s.size() &lt;&lt; endl;\n    \/\/ s.length()\u540c\u4e0a\n    s.push_back('A');\n    s.insert(s.begin(), 'B');\n    cout &lt;&lt; \"\u5c3e\u63d2A,\u5934\u63d2B\u540e\u7684s:\";\n    cout &lt;&lt; s &lt;&lt; endl;\n    s.append(\"cdeF\");\n    cout &lt;&lt; \"\u548ccdeF\u5b57\u7b26\u4e32\u62fc\u63a5\u540e\u7684s:\";\n    cout &lt;&lt; s &lt;&lt; endl;\n    \/\/ size_t\u66f4\u5b89\u5168\u7684\u5199\u6cd5\n    for (size_t i = 0; i &lt; s.size(); ++i)\n        s&#91;i] = tolower(s&#91;i]);\n    cout &lt;&lt; \"\u5168\u90e8\u5c0f\u5199\u5316\u7684s:\";\n    cout &lt;&lt; s &lt;&lt; endl;\n    for (size_t i = 0; i &lt; s.size(); ++i)\n        s&#91;i] = toupper(s&#91;i]);\n    cout &lt;&lt; \"\u5168\u90e8\u5927\u5199\u5316\u7684s:\";\n    cout &lt;&lt; s &lt;&lt; endl;\n    cout &lt;&lt; \"\u67e5\u627e\u7684\u7b2c\u4e00\u4e2aAA\u51fa\u73b0\u7684\u4f4d\u7f6e:\";\n    \/\/ \u8981\u627e\u7684\u5b50\u5b57\u7b26\u4e32\u4e0d\u5b58\u5728\u5c31\u4f1a\u8d4b\u7ed9find\u4e00\u4e2a\u6781\u5927\u7684\u503c\uff0c\u5c31\u662fstring::npos\n    if (s.find(\"AA\") == string::npos)\n        cout &lt;&lt; \"\u4e0d\u5b58\u5728\" &lt;&lt; endl;\n    else\n        cout &lt;&lt; s.find(\"AA\") &lt;&lt; endl;\n    cout &lt;&lt; \"\u67e5\u627e\u7684\u7b2c\u4e00\u4e2aaA\u51fa\u73b0\u7684\u4f4d\u7f6e:\";\n    if (s.find(\"aA\") == string::npos)\n        cout &lt;&lt; \"\u4e0d\u5b58\u5728\" &lt;&lt; endl;\n    else\n        cout &lt;&lt; s.find(\"aA\") &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/jiangqvweihuan.cn\/wp-content\/uploads\/2026\/03\/image-2.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"480\" height=\"243\" data-original=\"https:\/\/jiangqvweihuan.cn\/wp-content\/uploads\/2026\/03\/image-2.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-380\" style=\"width:344px;height:auto\"  sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u7ecf\u5178\u4f8b\u9898<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.luogu.com.cn\/problem\/P8835#ide\">P8835 [\u4f20\u667a\u676f #3 \u51b3\u8d5b] \u5b50\u4e32 &#8211; \u6d1b\u8c37<\/a><br><a href=\"https:\/\/ac.nowcoder.com\/acm\/contest\/200\/A\">A-\u751f\u65e5\u5bb4_\u725b\u5ba2\u7ec3\u4e60\u8d5b28<\/a><br><a href=\"https:\/\/ac.nowcoder.com\/acm\/contest\/9556\/B\">B-\u6015npy\u7684\u725b\u725b_\u725b\u5ba2\u7f16\u7a0b\u5dc5\u5cf0\u8d5bS2\u7b2c5\u573a &#8211; \u9752\u94dc&amp;\u767d\u94f6&amp;\u9ec4\u91d1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76f8\u4fe1\u5927\u5bb6\u5bf9\u4e8estring\u7684\u57fa\u7840\u4f7f\u7528\u5927\u62b5\u90fd\u5df2\u7ecf\u7089\u706b\u7eaf\u9752\uff0c\u6b64\u7bc7\u6587\u7ae0\u4ec5\u4ec5\u4f5c\u4e3a\u8865\u5145\u4e00\u4e9b\u6211\u7ecf\u5e38\u9700\u8981\u8bb0\u5fc6\u6216\u8005\u89c9\u5f97\u6709\u7528\u7684\u70b9\u4ee5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":151,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,12],"tags":[],"class_list":["post-378","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-article","category-programming-algorithm-road"],"_links":{"self":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/comments?post=378"}],"version-history":[{"count":7,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":446,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/378\/revisions\/446"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media\/151"}],"wp:attachment":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media?parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/categories?post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/tags?post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}