|
PRAGMA PROGRAM REFERENCE MANUAL
|
Index
|
All Operation
|
|
Expand All ADDENDUM
|
CUT
|
CT
|
Standard Verb
|
Miscellaneous Data Manipulation
|
Target = HEAD (HD), TAIL (TL), LENGTH (LT)
|
Cuts a number, an expression or the contents of a noun at a point indicated by another number, expression or noun. Puts the results into the target nouns HEAD, TAIL and LENGTH. CUT has no effect on the original item. If PRAGMA cannot find the cut point, no cut is made and the contents of the original is written into TAIL. HEAD will contain nothing or NULL (""). LENGTH will be 0. You can CUT after a number of characters or after a searched for string.
|
CUT the value ITEM after CUT POINT ITEM and CUT POINT can be a number, noun or expression. The cut is made after the place indicated by the number or character(s) indicated by CUT POINT. HEAD contains the left-hand result, TAIL the right-hand result of the cut. LENGTH contains a number of how many characters are in HEAD after the cut.
|
SEE ALSO: SPLIT / JOIN
|
DISCUSSION
CUT has no effect on the original item. It copies from the original item into HEAD and TAIL and leaves the original intact.
Since HEAD, TAIL and LENGTH are target nouns, if you cut them their original contents are lost. For example, if the content of HEAD after a CUT operation is the expression ABCD and you instruct PRAGMA to CUT HEAD after 2, the content of HEAD will be AB, and TAIL will contain CD. LENGTH will be 2.
Also, bear in mind that LENGTH is a target noun for INPUT, INPUT 0, $INPUT, RECEIVE, and JOIN. Any of these verbs could overwrite the contents of LENGTH.
If PRAGMA cannot find the cut point, no cut is made and the entire contents of the original are written into TAIL. HEAD will contain nothing, or Null (""). LENGTH will be zero. This occurs if the cut point is an expression that does not exist in the original item.
If the cut point is indicated by a number that contains a decimal (such as 5.5), the decimal will be ignored. For example, the instruction
CUT the value RENEWAL after 5.5
gives the following results:
HEAD will contain the first five characters of RENEWAL TAIL will contain the remaining characters of RENEWAL LENGTH will contain the integer 5
EXAMPLES
1. CUTTING AFTER AN EXPRESSION
In this example PRAGMA is instructed to cut the noun EMPLOYEE NAME after the comma. Since the comma is in quotes, it is treated as an expression.
CUT the value EMPLOYEE NAME after ","
The following table shows the results of this instruction, depending on the content of the original item. Brackets ( ] and [ ) are included in the HEAD and TAIL columns to show the exact contents of HEAD and TAIL, including spaces.
EMPLOYEE NAME HEAD TAIL LENGTH
Smith, John ]Smith,[ ] John[ 6
Smith,John ]Smith,[ ]John[ 6
Smith,John,Jr. ]Smith,[ ]John,Jr.[ 6
Only one cut after 1st comma.
Smith John ""(null) ]Smith John[ 0
No comma in the expression.
Smith John, ]Smith John,[ ""(null) 15
No characters after cut point,so TAIL is empty.
2. CUTTING AFTER A SPECIFIED NUMBER OF CHARACTERS
In the following example, an eight-digit number is cut twice to extract the fourth and fifth digits. The noun ACCOUNT NO contains the eight digits. The fourth and fifth digits represent the customer's credit limit, in hundreds of dollars.
VERB called CREDIT LIMIT CHECK
1 CUT the value ACCOUNT NO after 3 2 CUT the value TAIL after 2 3 MULTIPLY the value HEAD by the value 100 4 COPY the value PRODUCT to the noun CREDIT LIMIT 5 LOOKUP CURRENT BALANCE 6 ADD the value SALE AMOUNT to the value CURRENT BALANCE 7 IF the value SUM ">" the value CREDIT LIMIT do OVER CREDIT LIMIT else end
Following line 1, the first three digits of ACCOUNT NO are in HEAD, the last five digits are in TAIL, and LENGTH contains the number 3. After the cut in line 2, the fourth and fifth digits of ACCOUNT NO, which indicate the credit limit, are in HEAD, and the sixth an seventh digits of ACCOUNT NO are in TAIL. LENGTH contains the number 2. In line 3, the number in HEAD is multiplied by 100 to convert the limit to hundreds of dollars. Line 5 obtains the customer's current balance. Lines 6 and 7 add the value of the current sale to the balance and check the total against the credit limit; if the total exceeds the credit limit, the routine OVER CREDIT LIMIT is called.
3.1 DUMMY CUTS (NULL CUTS)
There may be times when you want to display or print a number in a left-aligned, no-comma format (as if it were an expression). For instance, you might want to display the number ] 123,456,789[ in the form ]123456789 [ (brackets indicate column boundaries).
You can do this with a dummy CUT operation, as shown in the next two examples. (The noun POPULATION contains the number 123,456,789.)
CUT the value 123,456,789 after ""
CUT the value POPULATION after ""
Both instructions result in 123456789 being written to HEAD, and "" (null) to TAIL. LENGTH will contain 9. The number can now be displayed in left-aligned format using the layout specification. Remember that the results of a CUT (in HEAD and TAIL) are always expressions:
DISPLAY LAYOUT using layout 13 the value HEAD
The number will be displayed in this way:
]123456789 [
3.2
A dummy cut can also be used to determine how many characters are contained in a noun. This could be used to center a heading of unknown length, as shown in the following example. This example also illustrates the CUT operation after a noun that contains a number.
VERB called CENTER HEADING
1 CUT the value HEADING after "" 2 SUBTRACT the value of LENGTH from the value of 80 3 DIVIDE the value DIFFERENCE by 2 4 SPLIT the value QUOTIENT 5 CUT the value 80 SPACES after INTEGER 6 PRINT the value HEAD 7 PRINT the value HEADING 8 PRINTER LINE FEED
After PRAGMA executes the dummy CUT in line 1, the entire contents of HEADING go into HEAD, TAIL is empty (""), and the noun LENGTH contains a number showing the number of characters in HEAD. To determine how many spaces to print before printing the noun HEADING, LENGTH is subtracted from the page width (that is, from 80), and the result is divided by two. This is done in lines 2 and 3. PRINTER LINE FEED, in line 8, causes the printer to output a line feed.
|
|
|
CustomWare® is a registered trademark of CustomWare Designs, Inc. All rights reserved.
CustomWare® is a registered servicemark of CustomWare Designs, Inc. All rights reserved.
All images and designs on this web site are copyrighted© 2021.
v
t
|
|