# System Functions

CVS( ) | Convert String

## Formats

1. | Reformat String: | CVS(data$,[cvs_code[:ctl_char$],...][,ERR=stmtref])
2. | Return Accent Table: | CVS( * )
3. | Return Character String: | CVS(num_val, num_val, num_val, ... ) (Added in PxPlus v7.00)

Where:

* | (asterisk) Returns the current 256-byte accent translation table.
ctl_char$ | Optional control character. String expression. Default: blank character.
cvs_code | Conversion type. Numeric expression. See the table in Format 1.
data$ | Data to convert. String expression.
num_val | Numeric values of the characters to be converted into a string.
stmtref | Program line number or statement label to which to transfer control.

## Returns

Converted value of string expression or accent translation table.

## Format 1

The CVS( ) function converts a string of data to different forms based on the numeric values used for cvs_code (e.g. to convert to uppercase, stripped string, etc.). The numeric expression tells the function the type of conversion to perform. If you append a : (colon) and string value, the control character used in the conversion will be the first character of the string; otherwise, it will be a space.

You can also use the function to return the current accent translation table and do translations based on it. See DEF CVS/DTE/LCS/UCS directives.

The value of cvs_code is made up of a series of binary values indicating:

Value | Conversion to Take Place
1 | Strip leading control characters.
2 | Strip trailing control characters.
4 | Convert string to uppercase.
8 | Convert string to lowercase.
16 | Replace non-printable characters with the control character.
32 | Replace multiple occurrences of the character with one.
64 | Replace $ with a defined currency symbol, comma with a defined thousands separator, and period with a defined decimal point. See the following system parameters: 'CU'= Currency Symbol 'DP'= Decimal Point Symbol 'TH'= Thousands Separator
128 | Replace a defined currency symbol, thousands separator and decimal point with $, comma, and period respectively (inverse of value 64 above).
256 | Convert string to mixed case (first letter of each word is uppercase, the rest of the letters are lowercase).
512 | Translate the string expression provided in data$ based on the current accent translation table.

## See Also

STP( ) Strip Leading/Trailing Characters
LCS( ) Return Lowercase String
UCS( ) Return Uppercase String

## Example

print "|",cvs(" The Cat ",1:" "),"|" | yields |The Cat|
print "|",cvs(" The Cat ",2:" "),"|" | yields |The Cat|
print "|",cvs(" The Cat ",39),"|" | yields |THE CAT| #### Note: 32+4+2+1=39 (you can use a sum)
print cvs("$$$123",32:"$") | yields $123

## Format 2

The CVS( * ) format returns a 256-byte string consisting of the character mapping table used for accented characters. Each byte in the table represents the character that the system uses when applying the accented character mapping for keyed files.

Example:

If the character Â is found in the text, its binary value (194 - Hex $C2$) will be used as the offset into the mapping table. For purposes of computing the offset, the first character in the table is considered offset 0, the second offset 1, and so on; therefore, an Â will be substituted with the character at position 195 in the string.

## Format 3

The CVS( ) function can also be used to return a character string based on a series of numeric values. When using Format 3, each numeric value passed is considered to be the binary UNICODE value for each character in the string to be returned.

Example:

The value of cvs(77,105,107,101) will return the string "Mike" since the binary value of "M" is 77, "i" is 105, etc.:

> cvs(77,105,107,101) = chr(77)+chr(105)+chr(107)+chr(101)

The primary purpose of this function is to provide for the easy conversion of UNICODE data into UTF-8.

(The CVS extension to provide UNICODE values was added in PxPlus v7.00.)