Book Image

LiveCode Mobile Development Cookbook

By : Dr. Edward Lavieri
Book Image

LiveCode Mobile Development Cookbook

By: Dr. Edward Lavieri

Overview of this book

Table of Contents (17 chapters)
LiveCode Mobile Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Replacing text


In this recipe, you will learn how to replace portions of text based on a search and match schema. We will use the replace command to accomplish this task.

How to do it...

Replacing sections of text can be a powerful part of a mobile app. Follow this recipe's steps to perform a global find-and-replace operation:

  1. Create a new main stack in LiveCode.

  2. Drag a new button to the card.

  3. Name the new button replaceText.

  4. Add the following code to the button:

    on mouseUp
      local tempText
      put "EMP001, EMP002, EMP003, EMP004, EMP005" into tempText
      replace "EMP" with "EMP#:" in tempText
      answer tempText
    end mouseUp

How it works...

We created a local variable (tempText) to hold our original text. Next, we used the replace command to change all occurrences of EMP to EMP#:. We then used the answer command to display the results.