Chapter 5. Expanding String Functionality Using Lists

In this chapter, we will cover the following topics:

  • Creating a list
  • Joining two lists
  • Joining list elements
  • Appending list elements
  • Assigning list elements to variables
  • Retrieving an element from a list
  • Inserting elements into a list
  • Determining the number of elements
  • Getting a list element
  • Repeating elements
  • Replacing elements
  • Reversing elements
  • Searching a list
  • Editing a list
  • Sorting a list
  • Splitting a string into a list

Introduction

Now that we have a firm grasp on the string type, let's look at the Tcl command list. As you might have discerned from the command name, this command is used to create and manage lists of information. While the various string handling commands allow for the creation of a string containing anything from a single character to larger text files, the list allows you to create, manipulate, and utilize a list of arguments in the same manner as a shopping list. In Tcl, each of the separate items in a list are referred to as elements.

In the following sections, we will examine not only the creation of a list, but also the many commands provided by Tcl to allow you to fully utilize the list and its elements. As a pre-requisite for the recipes in this chapter, launch the Tcl shell appropriately for your operating system. You can access Tcl from the command line to execute the commands.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.92