<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[文本中的字符运算]]></title><description><![CDATA[<p dir="auto"> </p>
<h2><a class="anchor-offset" name="先修科目"></a>先修科目</h2>
<ul>
<li><a href="/topic/303/%E4%BD%BF%E7%94%A8%E8%A7%92%E8%89%B2">使用角色</a></li>
</ul>
<p dir="auto"> </p>
<h2><a class="anchor-offset" name="介绍"></a>介绍</h2>
<p dir="auto"><strong>把一些“字符”写在一起</strong>就叫做<strong>文本</strong>。</p>
<p dir="auto"><em><strong>注意：汉字、字母、数字、符号和空格都被当做字符。</strong></em></p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/77aca10f-57a3-4dcb-96f8-357be4f6f13c.png" width="700" /><br />
 </p>
<h3><a class="anchor-offset" name="文本长度"></a>文本长度</h3>
<p dir="auto">文本的“<strong>长度</strong>”指的是文本中的<strong>字符</strong>数。例如，文本“创益编程，你好！”包含8个字符（包括标点符号），所以其长度就是8.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a5bee37e-f68f-43eb-93d3-14df1e9497c1.png" width="700" /><br />
 </p>
<h2><a class="anchor-offset" name="字符在文本中的位置"></a>字符在文本中的位置</h2>
<p dir="auto">文本中的字符被给予一个位置编号，从最左侧的位置1开始，一直增加到文本的长度。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7e92e70c-1131-4fe4-bf8c-423b28837ff7.png" width="700" /><br />
 </p>
<h3><a class="anchor-offset" name="文本的子串"></a>文本的子串</h3>
<p dir="auto"><strong>子串就是文本中的一段字符</strong>。例如，“你好”是“世界，你好！”的子串。我们可以用2个位置编号指定一个子串：第一个字符的位置和最后一个字符的位置。2个例子如下：</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7b1bdcd3-f490-4bd4-9ace-15cd36fd88c9.png" width="500" /></p>
<p dir="auto"> </p>
<h2><a class="anchor-offset" name="处理文本中字符的积木"></a>处理文本中字符的积木</h2>
<p dir="auto">在<strong>运算</strong>类别中有4个常见的报表积木用于处理字符。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0e9d785a-0a98-41a8-ad95-d0ac3514bc18.png" width="750" /><br />
 </p>
<h2><a class="anchor-offset" name="积木-在-文本-中-字符或子串-的位置"></a>积木：“在（文本）中（字符或子串）的位置”</h2>
<p dir="auto">这个积木<strong>告诉我们字符或子串在文本中的位置</strong>。</p>
<p dir="auto"><strong>注意：小写字母和大写字母算作不同。例如，在文本“None”中，字母“N”的位置为1，而字母“n”的位置为3。</strong></p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/40cbcfe6-5b7c-4bb2-a5e4-ef6ec4803ae4.gif" width="700" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> </p>
<h2><a class="anchor-offset" name="积木-文本-的第-位置编号-个字符"></a>积木：“（文本）的第（位置编号）个字符”</h2>
<p dir="auto">这个积木告诉我们文本的<strong>指定位置是什么字符</strong>。</p>
<p dir="auto"><strong>例如，文本“龙的传人”，位置4的字符为“人”</strong>。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6aac6620-a612-4555-a3c0-45231a217cc9.gif" width="700" style="border-radius:5px;border:1px solid #29622d" /><br />
 </p>
<h2><a class="anchor-offset" name="积木-文本-的字符数"></a>积木：“（文本）的字符数”</h2>
<p dir="auto">这个积木<strong>告诉我们文本的”长度“</strong>。</p>
<p dir="auto"><strong>例如，文本”君子成人之美，不成人之恶。“字符数为13</strong>（总共有13个字符）。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/2bcc5ce3-3ff1-47c3-bcd7-aca6d826056a.gif" width="700" style="border-radius:5px;border:1px solid #29622d" /><br />
 </p>
<h2><a class="anchor-offset" name="积木-提取-文本-的子串-从位置-起始位置-到-结束位置"></a>积木：“提取（文本）的子串 从位置（起始位置）到（结束位置）”</h2>
<p dir="auto">这个积木<strong>截取文本中2个位置之间的所有字符并生成一个新文本</strong>。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/74543864-8a72-44d0-9da2-e17b62360394.gif" width="700" style="border-radius:5px;border:1px solid #29622d" /><br />
 </p>
]]></description><link>https://forum.creaticode.com/topic/527/文本中的字符运算</link><generator>RSS for Node</generator><lastBuildDate>Fri, 08 May 2026 08:56:52 GMT</lastBuildDate><atom:link href="https://forum.creaticode.com/topic/527.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Aug 2022 06:08:42 GMT</pubDate><ttl>60</ttl></channel></rss>