User:Brian P. Josey/Notebook/2010/08/26

From OpenWetWare
Jump to: navigation, search
Owwnotebook icon.png Project name Report.pngMain project page
Resultset previous.pngPrevious entry      Next entryResultset next.png

Strings and File I/O

A string is simply a sequence of letters that are platform independent, and can be used for a couple of purposes, such as creating simple text messages, storing data to a disk, or use in prompts for the user. The string can be generated on its own, as a single and simple string, or as a part of a table. In a table, each cell is itself a string. To generate a table of strings with column and row headers, any numerical data needs to first be converted into a string, and then a 1-D array for the headers needs to be built and put together. This array can then be displayed as a table.

String Functions

There are several useful functions that act on strings. The are:

  • String Length takes a string, and returns the length of it. The length is measured in the number of characters, including spaces, or bytes in the string.
  • Concatenate Strings this function will take several strings, and arrays of strings, and concatenate, put together, them into a single output string.
  • String Subset will allow you to remove a substring from a larger string. To do this, it starts at a specified character position, and then takes that character and the next set of characters that is specified by the user. When using this function, the first character in the string always has a position of zero. For example, if there is a string "Jurassic Park is an amazing movie", the user could ask for a substring starting at character 9, the "P" in "Park" and ask for a substring four characters long returning "Park".
  • Match Pattern will find a pattern in the string after a certain offset, and split the original string into three parts, everything that came before the matched pattern, the matched pattern, and everything that came afterwords.