Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Operators for Substring of Text

Operators for Substring of Text

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 794 Views
  • 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.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

     

    Prerequisite

    • Operators for Characters in Text

    Introduction

    You learned about the operators for characters in text before. You can also operate on “substrings” of text. A “substring” is a segment of the text. It might contain one or more characters from the text that are connected with each other.

    For example, for the text “abcde”, you can take the characters in positions 2, 3 and 4 to create a substring “bcd”:

     

    Note that you can not take “b” and “d” to form a substring of “abcde”. Although they are both in the text, they are not connected (since they are separated by “c”).

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

     
     

    Whether a Text Contains a Substring

    A most common use case is to check if a text contains a substring in it. For example, for the text “abcde”, “ab” is a substring, “bd” is not. Note that uppercase and lowercase letters are treated as the same, so “BC” is the same as “bc”.

     
     

    Position of a Substring in a Text

    When a substring is in a text, you can also get its starting position within the text. For example, the substring “bc” is in position 2 to 3 in the text “abcde”, so its starting position is 2.

    If the substring is not found in the text, then a value of 0 will be returned. Note that uppercase and lowercase letters are treated as the same.

     
     

    Extract a Substring from a Text

    If you know the starting and ending positions of the substring you are looking for, you can use the “substring of” block to extract that substring. If the positions are not valid, then an empty value will be returned.

     
     

    Replace a Substring in a Text

    You can replace a substring of a text with another text. For example, in the text “How do you do?”, the substring “do” appears 2 times. We can replace them with another text, like “did”:

    The 3 inputs are the substring to be replaced, the new text to replace with, and the text to be changed.

    1 Reply Last reply
    0

    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
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode