Difference between revisions of "Working With String Data in Recital"
From Recital Documentation Wiki
Yvonnemilne (Talk | contribs) (→String Conversion Functions) |
Yvonnemilne (Talk | contribs) (→Recital printf Formatting Specifiers) |
||
| Line 13: | Line 13: | ||
===Printing Formatted Strings in Recital=== | ===Printing Formatted Strings in Recital=== | ||
===Recital printf Formatting Specifiers=== | ===Recital printf Formatting Specifiers=== | ||
| + | |||
| + | {| class="wikitable" | ||
| + | !Formatting option||Description | ||
| + | |- | ||
| + | |%s||Convert to character string (similar to using [[ETOS()]] or [[TOSTRING()]] | ||
| + | |- | ||
| + | |%d||For date parameters | ||
| + | |- | ||
| + | |%f||For floating point numeric parameters | ||
| + | |- | ||
| + | |%y||For currency parameters | ||
| + | |- | ||
| + | |%t||For datetime parameters | ||
| + | |- | ||
| + | |%T||For datetime parameters; character day is also displayed | ||
| + | |- | ||
| + | |%l||For logical parameters: True, False | ||
| + | |- | ||
| + | |%L||For logical parameters: Yes, No | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | |||
| + | Formatting sequences can also contain the following options. These are specified in order, between the '%' and the data type letter. | ||
| + | |||
| + | |||
| + | {| class="wikitable" | ||
| + | !Formatting option||Description | ||
| + | |- | ||
| + | |-||Left-justify | ||
| + | |- | ||
| + | |n||Left pad with spaces to width n | ||
| + | |- | ||
| + | |n.p||Left pad with spaces to width n and include the decimal point and p decimal places (%f only) | ||
| + | |- | ||
| + | |} | ||
| + | |||
| + | '''Example code''' | ||
| + | <code lang="recital"> | ||
| + | // When %s is specified, the corresponding argument is converted to | ||
| + | // character format (similar to specifying etos()). | ||
| + | // Widths correspond to the default values, e.g. numerics are 10 | ||
| + | printf('It is %s, %s to be more precise\n',year(date()),datetime()) | ||
| + | printf('The value of pi is %s\n',pi()) | ||
| + | printf('They cost %s per %s\n',$99,100) | ||
| + | printf('Logicals can be %s or %s\n',.T.,.F.) | ||
| + | // Formatting sequences can contain a width, which will left pad with spaces | ||
| + | printf('Right-justify and pad left: %10s this\n','Like') | ||
| + | // Left justify by placing a '-' directly following the '%' character | ||
| + | printf('Left-justify and pad right: %-10s this\n','Like') | ||
| + | // %d is for numerics | ||
| + | printf('It is %d\n',year(date())) | ||
| + | // %t and %T are for formating datetime data types. | ||
| + | printf('It is %d, %t to be more precise\n',year(date()),datetime()) | ||
| + | printf('It is %d, %T to be even more precise\n',year(date()),datetime()) | ||
| + | // %f is for floating point numerics | ||
| + | printf('The value of pi is %f\n',pi()) | ||
| + | // Decimal places can also be specified for floating point numerics (%f) | ||
| + | printf('The value of pi to two decimal places is %4.2f\n',pi()) | ||
| + | // %y is for formatting currency data types | ||
| + | printf('They cost %y per %d\n',$99,100) | ||
| + | printf('They cost %y per %d\n',$99,1000) | ||
| + | printf('They cost %y per %d\n',$99,10000) | ||
| + | //%l and %L are for formatting logical datatypes. | ||
| + | printf('Logicals can be %l or %l\n',.T.,.F.) | ||
| + | printf('Logicals can also be %L or %L\n',.T.,.F.) | ||
| + | </code> | ||
| + | |||
| + | '''Output''' | ||
| + | <pre> | ||
| + | It is 2009, 11/11/2009 11:41:51 AM to be more precise | ||
| + | The value of pi is 3.1415926 | ||
| + | They cost $99.0000 per 100 | ||
| + | Logicals can be True or False | ||
| + | Right-justify and pad left: Like this | ||
| + | Left-justify and pad right: Like this | ||
| + | It is 2009 | ||
| + | It is 2009, 11/11/2009 11:41:51 AM to be more precise | ||
| + | It is 2009, Wednesday November 11 2009 11:41:51 to be even more precise | ||
| + | The value of pi is 3.141593 | ||
| + | The value of pi to two decimal places is 3.14 | ||
| + | They cost $99.0000 per 100 | ||
| + | They cost $99.0000 per 1000 | ||
| + | They cost $99.0000 per 10000 | ||
| + | Logicals can be True or False | ||
| + | Logicals can also be Yes or No | ||
| + | </pre> | ||
| + | |||
===Finding the Length of a Recital String=== | ===Finding the Length of a Recital String=== | ||
Revision as of 15:03, 11 November 2009
Contents
- 1 Working With String Data in Recital
- 1.1 Changing the Case of a String
- 1.2 Converting to and from ASCII Values
- 1.3 Printing Formatted Strings in Recital
- 1.4 Recital printf Formatting Specifiers
- 1.5 Finding the Length of a Recital String
- 1.6 Converting a String Into an Array
- 1.7 Converting an Array into a String
- 1.8 String Conversion Functions
- 1.9 Removing Leading and Trailing Whitespace from a Recital String
- 1.10 Comparing Strings in Recital
- 1.11 String Comparison Functions Return Value
- 1.12 Accessing and Modifiying Characters in String
- 1.13 Searching for Characters and Substrings in a Recital String
- 1.14 Extracting and Replacing Substrings in Recital
- 1.15 Replacing All Instances of a Word in a Recital String
- 1.16 Miscellaneous String Functions
- 1.17 Summary
Working With String Data in Recital
Changing the Case of a String
See Also
Table of Contents
- strtolower() - convert a string to lower case
- strtoupper() - convert a string to upper case
- ucfirst() - convert a string to lower case with the first character of each word in upper case
Converting to and from ASCII Values
Printing Formatted Strings in Recital
Recital printf Formatting Specifiers
| Formatting option | Description |
|---|---|
| %s | Convert to character string (similar to using ETOS() or TOSTRING() |
| %d | For date parameters |
| %f | For floating point numeric parameters |
| %y | For currency parameters |
| %t | For datetime parameters |
| %T | For datetime parameters; character day is also displayed |
| %l | For logical parameters: True, False |
| %L | For logical parameters: Yes, No |
Formatting sequences can also contain the following options. These are specified in order, between the '%' and the data type letter.
| Formatting option | Description |
|---|---|
| - | Left-justify |
| n | Left pad with spaces to width n |
| n.p | Left pad with spaces to width n and include the decimal point and p decimal places (%f only) |
Example code
// When %s is specified, the corresponding argument is converted to // character format (similar to specifying etos()). // Widths correspond to the default values, e.g. numerics are 10 printf('It is %s, %s to be more precise\n',year(date()),datetime()) printf('The value of pi is %s\n',pi()) printf('They cost %s per %s\n',$99,100) printf('Logicals can be %s or %s\n',.T.,.F.) // Formatting sequences can contain a width, which will left pad with spaces printf('Right-justify and pad left: %10s this\n','Like') // Left justify by placing a '-' directly following the '%' character printf('Left-justify and pad right: %-10s this\n','Like') // %d is for numerics printf('It is %d\n',year(date())) // %t and %T are for formating datetime data types. printf('It is %d, %t to be more precise\n',year(date()),datetime()) printf('It is %d, %T to be even more precise\n',year(date()),datetime()) // %f is for floating point numerics printf('The value of pi is %f\n',pi()) // Decimal places can also be specified for floating point numerics (%f) printf('The value of pi to two decimal places is %4.2f\n',pi()) // %y is for formatting currency data types printf('They cost %y per %d\n',$99,100) printf('They cost %y per %d\n',$99,1000) printf('They cost %y per %d\n',$99,10000) //%l and %L are for formatting logical datatypes. printf('Logicals can be %l or %l\n',.T.,.F.) printf('Logicals can also be %L or %L\n',.T.,.F.)
Output
It is 2009, 11/11/2009 11:41:51 AM to be more precise The value of pi is 3.1415926 They cost $99.0000 per 100 Logicals can be True or False Right-justify and pad left: Like this Left-justify and pad right: Like this It is 2009 It is 2009, 11/11/2009 11:41:51 AM to be more precise It is 2009, Wednesday November 11 2009 11:41:51 to be even more precise The value of pi is 3.141593 The value of pi to two decimal places is 3.14 They cost $99.0000 per 100 They cost $99.0000 per 1000 They cost $99.0000 per 10000 Logicals can be True or False Logicals can also be Yes or No
Finding the Length of a Recital String
See Also
Table of Contents
- strlen() - return the numeric length of a string
Converting a String Into an Array
Converting an Array into a String
String Conversion Functions
See Also
Table of Contents
- ctod() - perform character to date conversion
- dtoc() - perform date to character conversion
- dtos() - perform date to string conversion
- etos() - perform expression to string conversion
- stod() - perform string to date conversion
- val() - perform string to numeric conversion