{"id":3377,"date":"2024-11-10T09:43:20","date_gmt":"2024-11-10T01:43:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3377\/"},"modified":"2024-11-10T09:43:20","modified_gmt":"2024-11-10T01:43:20","slug":"js%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%ad%97%e7%ac%a6%e5%a4%a7%e5%b0%8f%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3377\/","title":{"rendered":"js\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199"},"content":{"rendered":"<blockquote><p>\n  \u5728 javascript \u4e2d\uff0c\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u7684\u65b9\u6cd5\u5305\u62ec\uff1acharcodeat() \u65b9\u6cd5\uff1a\u8fd4\u56de\u5b57\u7b26\u7684 unicode \u7f16\u7801\uff0c\u5e76\u533a\u5206\u5927\u5c0f\u5199\u5b57\u6bcd\u7684\u7f16\u7801\u8303\u56f4\u3002touppercase() \u548c tolowercase() \u65b9\u6cd5\uff1a\u53ef\u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u5927\u5c0f\u5199\u5f62\u5f0f\uff0c\u5e76\u53ef\u4ee5\u6bd4\u8f83\u5176\u5927\u5c0f\u5199\u662f\u5426\u76f8\u540c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110811061793584.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u63d2\u56fe\" alt=\"js\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 JavaScript \u4e2d\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199<\/strong><\/p>\n<p><strong>\u6982\u8ff0<\/strong><\/p>\n<p>\u5728 JavaScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 charCodeAt() \u65b9\u6cd5\u548c toUpperCase() \u548c toLowerCase() \u65b9\u6cd5\u6765\u5224\u65ad\u5b57\u7b26\u7684\u5927\u5c0f\u5199\u3002<\/p>\n<p><strong>charCodeAt() \u65b9\u6cd5<\/strong><\/p>\n<p>charCodeAt() \u65b9\u6cd5\u8fd4\u56de\u6307\u5b9a\u5b57\u7b26\u7684 Unicode \u7f16\u7801\u3002\u5927\u5c0f\u5199\u5b57\u7b26\u5177\u6709\u4e0d\u540c\u7684 Unicode \u7f16\u7801\u8303\u56f4\uff1a<\/p>\n<ul>\n<li>\u5927\u5199\u5b57\u6bcd\uff1a65-90<\/li>\n<li>\u5c0f\u5199\u5b57\u6bcd\uff1a97-122<\/li>\n<\/ul>\n<pre>\/\/ \u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u5927\u5199\nconst isUpperCase = (char) =&gt; char.charCodeAt(0) &gt;= 65 &amp;&amp; char.charCodeAt(0) &lt;= 90;\n\n\/\/ \u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u5c0f\u5199\nconst isLowerCase = (char) =&gt; char.charCodeAt(0) &gt;= 97 &amp;&amp; char.charCodeAt(0) &lt;= 122;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>toUpperCase() \u548c toLowerCase() \u65b9\u6cd5<\/strong><\/p>\n<p>toUpperCase() \u65b9\u6cd5\u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u5927\u5199\u5f62\u5f0f\uff0ctoLowerCase() \u65b9\u6cd5\u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u5c0f\u5199\u5f62\u5f0f\u3002\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u6765\u6bd4\u8f83\u5b57\u7b26\u662f\u5426\u76f8\u540c\uff1a<\/p>\n<pre>\/\/ \u5224\u65ad\u4e24\u4e2a\u5b57\u7b26\u662f\u5426\u5927\u5c0f\u5199\u76f8\u540c\nconst isSameCase = (char1, char2) =&gt; char1.toUpperCase() === char2.toUpperCase();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<pre>const char = 'a';\n\nconsole.log(`Unicode \u7f16\u7801\uff1a${char.charCodeAt(0)}`);\nconsole.log(`\u662f\u5927\u5199\u5b57\u6bcd\uff1a${isUpperCase(char)}`);\nconsole.log(`\u662f\u5c0f\u5199\u5b57\u6bcd\uff1a${isLowerCase(char)}`);\n\nconst sameCase = isSameCase('A', 'a');\nconsole.log(`\u5927\u5c0f\u5199\u76f8\u540c\uff1a${sameCase}`);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Unicode \u7f16\u7801\uff1a97\n\u662f\u5927\u5199\u5b57\u6bcd\uff1afalse\n\u662f\u5c0f\u5199\u5b57\u6bcd\uff1atrue\n\u5927\u5c0f\u5199\u76f8\u540c\uff1atrue<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 javascript \u4e2d\uff0c\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199\u7684\u65b9\u6cd5\u5305\u62ec\uff1acharcodeat() \u65b9\u6cd5\uff1a\u8fd4\u56de\u5b57\u7b26\u7684 unicode \u7f16\u7801\uff0c\u5e76\u533a\u5206\u5927\u5c0f\u5199\u5b57\u6bcd\u7684\u7f16\u7801\u8303\u56f4\u3002touppercase() \u548c tolowercase() \u65b9\u6cd5\uff1a\u53ef\u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u5927\u5c0f\u5199\u5f62\u5f0f\uff0c\u5e76\u53ef\u4ee5\u6bd4\u8f83\u5176\u5927\u5c0f\u5199\u662f\u5426\u76f8\u540c\u3002 \u5728 JavaScript \u4e2d\u5224\u65ad\u5b57\u7b26\u5927\u5c0f\u5199 \u6982\u8ff0 \u5728 JavaScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 charCodeAt() \u65b9\u6cd5\u548c toUpperCase() \u548c toLowerCase() \u65b9\u6cd5\u6765\u5224\u65ad\u5b57\u7b26\u7684\u5927\u5c0f\u5199\u3002 charCodeAt() \u65b9\u6cd5 charCodeAt() \u65b9\u6cd5\u8fd4\u56de\u6307\u5b9a\u5b57\u7b26\u7684 Unicode \u7f16\u7801\u3002\u5927\u5c0f\u5199\u5b57\u7b26\u5177\u6709\u4e0d\u540c\u7684 Unicode \u7f16\u7801\u8303\u56f4\uff1a \u5927\u5199\u5b57\u6bcd\uff1a65-90 \u5c0f\u5199\u5b57\u6bcd\uff1a97-122 \/\/ \u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u5927\u5199 const isUpperCase = (char) =&gt; char.charCodeAt(0) &gt;= 65 &amp;&amp; char.charCodeAt(0) &lt;= 90; \/\/ \u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u5c0f\u5199 const isLowerCase = (char) =&gt; char.charCodeAt(0) &gt;= [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3377","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3377"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3377\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}