



    ________________________________________________________________________
                                       Chapter 7: Chunk Expressions   59
    ________________________________________________________________________


    CHAPTER SEVEN: CHUNK EXPRESSIONS

    In an English-like intuitive manner, chunking precisely accesses any
    piece of data from anywhere within your pad. You can specify individual
    or groups of characters, words, items or lines from a container, or even
    pinpoint parts of other chunks. The following are examples of chunking
    used to access information:

    put char 1 of page field 1 into msg;

    print the last word of field "Last Name";

    delete the first line of MyWordList;


    SIMPLE CHUNK EXPRESSIONS

    There are three forms of a simple chunk expression. These examples show
    each form using character (abbreviated char) chunks.

    The first form specifies any character within the container, in this
    case the first character.

    char 1 of page field 1

    The second form specifies a range of characters (a group) within the
    container, in this case the first 10 characters.

    char 1 to 10 of page field 1

    The last uses an ordinal to specify the character within the container,
    in this case, the third character.

    the third character of page field 1



    ________________________________________________________________________
                                       Chapter 7: Chunk Expressions   60
    ________________________________________________________________________


    The available ordinals are:

    Ordinal:        Example Chunk:
    ------------------------------------------------------------
    first           the first character of field 1

    second          the second character of field 1

    third           the third character of field 1

    fourth          the fourth character of field 1

    fifth           the fifth character of field 1

    sixth           the sixth character of field 1

    seventh         the seventh character of field 1

    eight           the eight character of field 1

    ninth           the ninth character of field 1

    tenth           the tenth character of field 1

    any             any character of field 1

    middle          the middle character of field 1

    last            the last character of field 1


    The special ordinals any, middle, and last depend on the contents of the
    container. The ordinal any specifies a random character, word, item, or
    line, and middle selects the middle character, word, item, or line.


    CHARACTER CHUNKS

    Character chunks are determined by offsets within the container. The
    following example returns the character at position 5 ("o").

    char 5 of "hello there"

    All characters, including spaces and carriage returns, are treated as
    chunking characters.


    WORD CHUNKS

    Word chunks are delimited by spaces (" ") or carriage returns. For
    example,



    ________________________________________________________________________
                                       Chapter 7: Chunk Expressions   61
    ________________________________________________________________________
    word 2 of "this is a test"

    will return the word "is". Notice that the word itself is returned
    stripped of any spaces or carriage returns that surround it.



    ________________________________________________________________________
                                       Chapter 7: Chunk Expressions   62
    ________________________________________________________________________


    ITEM CHUNKS

    Item chunks are delimited by commas (","). For example,

    item 2 of "doctor,lawyer,clerk,"

    will return "lawyer". In fact, the text between the first and second
    comma is returned, even if there are spaces and many words. For example,

    item 2 of "doctor Williams  ,lawyer Seeley  ,clerk Betty"
    will return "lawyer Seeley  ". Notice that the commas are not returned.


    LINE CHUNKS

    Line chunks are delimited by carriage returns. For example, if there is
    a field with the following text:

    doctor Williams
    lawyer Seeley
    clerk Betty

    the following chunk expression

    line 2 of field 1

    will return "lawyer Seeley". Like item chunks, anything between the
    carriage returns is returned, including spaces, words and items. Since
    the text in fields may be word wrapped, the actual number of lines in a
    field and the number of lines on the screen may not always be the same.
    Also, line chunks are returned without their carriage return delimiters.


    SPECIFYING CHUNKS OF CHUNKS

    In addition to simple chunking expressions, combine chunking types to
    further pinpoint a piece of text. Always order the statement from the
    smallest chunk to the largest chunk. Each chunk type is separated by the
    word of. For example:

    char 1 of word 6 of page field 1

    char 5 to 8 of the second item of field "Address"

    char 1 of word 2 of item 6 of the last line of field 1 of
    page 10

    the middle item of any line of field "Zippy Messages"



    ________________________________________________________________________
                                       Chapter 7: Chunk Expressions   63
    ________________________________________________________________________


    CHUNKING DESTINATIONS

    In addition to retrieving pieces of text, you can use chunk expressions
    as destinations for text. For example:

    put "hello" into word 6 of page field 1;
    put pg fld 2 before the first line of pg fld 1;

    When pinpointing a chunk as a destination, specify if you want to
    replace the chunk (by using into), insert before the chunk (by using
    before) or insert after the chunk (by using after).

    If you use into, the expression supplied will replace the specified
    destination chunk. For example, if field 1 contains "HyperPAD", then the
    command:

    put "Extension" into char 6 to 8 of "HyperPAD"

    will change field 1 to "HyperExtension".

    If you specify a non-existent item as the destination, HyperPAD will
    create blank items as filler. For example, suppose field 1 contains
    "John Smith", then the following statement

    put "Sue" into item 4 of field 1;

    will change field 1 to "John Smith,,,Sue". Notice that HyperPAD inserted
    3 commas in order to make "Sue" the fourth item. The same will happen
    for line chunks as well.

    Using before and after as destinations with items and lines inserts a
    delimiter. For example, the following statement

    put "Hello There" after the last line of page field 1;

    appends a line after page field 1 and sets it to "Hello There". HyperPAD
    inserts a carriage return to create the correct number of lines. The
    same is true of items.