• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 10. Controlling Text > Analyzing Strings with the String Object

Analyzing Strings with the String Object

Use the methods of the String object to identify a character or characters in a string. The following tasks analyze input text boxes to verify that the viewer has entered the required information.

To identify the position of a character:

1.
Select the text tool from the Tools window, and drag out a text box onto the Stage. In the Text Options panel, select Input Text and Single Line from the pull-down menus. Enter a variable name for this input text box (Figure 10.55).

Figure 10.55. Name your input text box myString.


2.
Create a button symbol, and place an instance of it on the Stage. Select it, and open the Actions panel.

3.
Choose Actions > set variable.

4.
In the Variable field, enter a variable name. In the Value field, enter the variable name of your input text box. Then, with the cursor still in the Value field, choose Objects > String > indexOf.

The indexOf method appears after your input text variable. The arguments searchString and fromIndex are highlighted. The parameter searchString is the specific character you want to identify in the string. The parameter fromIndex is the starting position in the string. The parameter fromIndex is optional (Figure 10.56).

Figure 10.56. Assign the indexOf method to myString.


5.
Replace the parameter searchString with the character you want to find. Make sure you include quotation marks around the character. Delete the fromIndex parameter. Check the Expression box next to the Value field (Figure 10.57).

Figure 10.57. This indexOf method searches myString for the % sign and puts the index into the variable characterPosition.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint