Logo-strings

提供:Dev Guides
移動先:案内検索

ロゴ-文字列

英数字の任意のシーケンス。たとえば、「america」、「emp1234」など。 文字列の例です。 文字のカウントは、すべての文字列プロセスの中で最も基本的なものです。 質問 stringlength "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

上記の手順では、「s」は入力文字列を含む変数です。 変数inputstringには、入力文字列のコピーが含まれます。 変数カウントは0で初期化されます。 whileループで、条件は文字列が空になったかどうかをチェックします。 各ループカウントでは、長さカウントを保持するために変数が1ずつ増加しています。 ステートメント print first:s は、「s」に格納されている文字列の最初の文字のみを出力します。

ステートメント make "s butfirst:s は、最初の文字を除く部分文字列を取得します。 whileループを終了した後、文字数または入力文字列の長さを出力しました。 以下は、コードの実行と出力です。

文字列