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:
Create a new main stack in LiveCode.
Drag a new button to the card.
Name the new button
replaceText
.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.