文本中的字符运算
-
先修科目
介绍
把一些“字符”写在一起就叫做文本。
注意:汉字、字母、数字、符号和空格都被当做字符。

文本长度
文本的“长度”指的是文本中的字符数。例如,文本“创益编程,你好!”包含8个字符(包括标点符号),所以其长度就是8.

字符在文本中的位置
文本中的字符被给予一个位置编号,从最左侧的位置1开始,一直增加到文本的长度。

文本的子串
子串就是文本中的一段字符。例如,“你好”是“世界,你好!”的子串。我们可以用2个位置编号指定一个子串:第一个字符的位置和最后一个字符的位置。2个例子如下:

处理文本中字符的积木
在运算类别中有4个常见的报表积木用于处理字符。

积木:“在(文本)中(字符或子串)的位置”
这个积木告诉我们字符或子串在文本中的位置。
注意:小写字母和大写字母算作不同。例如,在文本“None”中,字母“N”的位置为1,而字母“n”的位置为3。

积木:“(文本)的第(位置编号)个字符”
这个积木告诉我们文本的指定位置是什么字符。
例如,文本“龙的传人”,位置4的字符为“人”。

积木:“(文本)的字符数”
这个积木告诉我们文本的”长度“。
例如,文本”君子成人之美,不成人之恶。“字符数为13(总共有13个字符)。

积木:“提取(文本)的子串 从位置(起始位置)到(结束位置)”
这个积木截取文本中2个位置之间的所有字符并生成一个新文本。

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login