Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Operators for Characters in Text

    2D Blocks
    1
    1
    272
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

       

      Introduction

      A “text” is also called a “string”. It is made of one or more characters. Each character can be a letter (such as “a” or “X”), a digit (0 to 9) or a symbol (such as “+” or “!”).

      We can use text to represent all kinds of information, such as the name of a person, the title of a book, or the content of a piece of news.

      Let’s look at some operator blocks for working with text below.

       
       

      Length of a Text

      The “length” of a text refers to the number of characters in it.

      For example, the text “hello” contains 5 letters, so its length is 5. The text “Let’s go!” contains 6 letters and 3 symbols (including the space), so its length is 9.

       
       

      Reading the Character at a Position

      You can get the character at any position in a text using the “letter (position) of (text)” block. Note that this block will not only find the letter by its position, but also find the digit or symbol at a position.

       
      Note that if you use a position that is less than 1 or more than the length of the text, this block will report an empty value (not the same as the “space” symbol).

       
       

      Get the Position of A Character

      We can also ask for the position of a character in a text. For example, in the text “abcd”, the letter “b” is at position 2, and “d” is at position 4:

       

      If a text contains the same character multiple times, this block will report the position of the first one:

       
      If the character is not found in the text, a value of 0 will be reported. Note that upper case and lower case letters are treated as the same.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post