📜  Logo-字符串

📅  最后修改于: 2020-11-03 07:28:23             🧑  作者: Mango


任何字母数字字符序列,例如“ america”,“ emp1234”等,都是字符串的示例。计数字符是所有字符串处理中最基本的。问题字符串长度“ abc12ef”的答案由以下过程给出-

to stringlength :s
   make "inputstring :s
   make "count 0
   while [not emptyp :s] [
      make "count :count + 1
      print first :s
      make "s butfirst :s
   ]
   print (sentence :inputstring "has :count "letters)
end

在上述过程中,“-”是包含输入字符串的变量。变量inputstring包含输入字符串的副本。变量count初始化为0。在while循环中,条件检查字符串是否为空。在每个循环计数中,变量将增加1以保持长度计数。语句print first:s ,仅打印存储在s中的字符串的第一个字符。

语句make“ s butfirst:s ,检索不包括第一个字符的子字符串。退出while循环后,我们打印了字符数或输入字符串的长度。以下是代码的执行和输出。

弦乐