CVT() Function - BBj Specific Information

For this topic's original documentation, see CVT() Function - Pixel, Character, and Semicharacter Unit Conversion.

BBj-Specific Information

The unit conversion values returned for BBj will not necessarily be the same as the values returned for Visual PRO/5. The font used for conversion is the default control font. It may return slightly different values than Visual PRO/5.

Syntax

CVT(string,int{,ERR=lineref})

Description

In BBj 15.00 and higher, the CVT(string,int) function emulates the Thoroughbred Basic CVT function.

Parameter

Description

string

String to be converted.

int

Integer identifying conversion functions, according to the following table.

Value

Description

0

Do nothing.

1

Clear the high order bit in each byte, equivalent toAND(string,fill(len(string),$7f$)).

2

Strip out all tabs and spaces.

4

Strip out all $00$ through $1F$ (ASCII control characters below space).

8

Strip out all leading tabs and spaces.

16

Replace multiple spaces with a single space and multiple tabs with a single tab.

32

Convert characters to uppercase.

64

Convert "[" to "(" and "]" to ")".

128

Strip out trailing tabs and spaces.

256

Don't convert characters within double quotes.

512

Swap adjacent bytes, equivalent toSWAP(string,$01$).

1024

Strip out everything but spaces, letters, and numbers.

2048

Same as option 1.

4096

Convert characters to lowercase.

8192

Reverse the entire string. CVT("Hello world",8192)returns"dlrow olleH". If specified, this option is always applied first.

16384

Convert nonprintable characters to spaces.

32768

First strip trailing $00$ characters, then strip any trailing $0A$ or $0D0A$ sequences.

ERR=lineref

Branch to be taken if an error occurs during execution.


A combination of operations may be specified by adding functional values. For example, CVT(A$,40) strips leading tabs and spaces and converts to upper case. CVT(A$,40) is equivalent to CVT(A$,32+8), which is equivalent to CVT(CVT(A$,8),32). When multiple operations are combined in a single CVT() function, they are guaranteed to be applied in ascending numeric order (with one exception, 8192, noted above). For example, CVT(CVT(A$,8+16384),16) first strips leading tabs and spaces, then converts non-printable characters to spaces, and finally replaces multiple spaces with a single space. To apply multiple options in a different order, execute the CVT() in a nested manner as shown in the above example.

Example

rem ' cvt.txt
rem ' https://documentation.basis.cloud/BASISHelp/WebHelp/commands/bbj-commands/cvt_function_bbj_specific_information.htm
print "Running "+pgm(-2)
rem ' 0 = Do not edit.
if cvt("xyzzy",0)<>"xyzzy" then escape
if cvt($000a8a$,0)<>$000a8a$ then escape
rem ' 1 = Clear the high-order (leftmost) bit in each byte.
if cvt($00$,1)<>$00$ then escape
if cvt($8a$,1)<>$0a$ then escape
if cvt($00$,1+256)<>$00$ then escape
if cvt($8a$,1+256)<>$0a$ then escape
if cvt($00$+""""+$ff$+"""",1+256)<>$00$+""""+$ff$+"""" then escape
if cvt($8a$+""""+$ff$+"""",1+256)<>$0a$+""""+$ff$+"""" then escape
rem ' 2 = Remove all blanks and tabs.
if cvt("  This  is a   test  . ",2)<>"Thisisatest." then escape
if cvt($0909$+"  This  is a   test  . "+$090900$,2)<>"Thisisatest."+$00$ then escape
if cvt($0909$+"  This  is a   test  . "+$090900$,2+256)<>"Thisisatest."+$00$ then escape
if cvt($0909$+"  This  is a ""quote with spaces""  test  . "+$090900$,2+256)<>"Thisisa""quote with spaces""test."+$00$ then escape
rem ' 4 = Remove unprintable characters below space ($00$ through $1F$).
if cvt("Testing"+$000a01$+" 123",4)<>"Testing 123" then escape
if cvt("Testing"+$000a01$+" 123",4+256)<>"Testing 123" then escape
if cvt("Testing"+$000a01$+""""+$0a$+""" 123",4+256)<>"Testing"""+$0a$+""" 123" then escape
cafe! = new String("caf"+$c3a9$,"UTF-8")
if cvt(cafe!,4)<>cafe! then escape
rem ' However, when PRM CVTSTRIP is set, characters from $80$ through $9F$ 
rem ' will also be removed because they are first stripped to $00 through $1F$.
rem ' 8 = Remove all leading spaces and tabs (option 256 is ignored).
if cvt("   "+$00$+"testing  ",8)<>$00$+"testing  " then escape
if cvt("   "+$09$+"testing "+$09$,8)<>"testing "+$09$ then escape
rem ' 16 = Reduce each multiple occurrence of spaces and tabs to one each.
if cvt("The  quick   brown    fox",16)<>"The quick brown fox" then escape
if cvt($090909$+"tab"+$090909$+"   space   ",16)<>$09$+"tab"+$09$+" space " then escape
if cvt("The  quick   brown    fox",16+256)<>"The quick brown fox" then escape
if cvt($090909$+"tab"+$090909$+"   space   ",16+256)<>$09$+"tab"+$09$+" space " then escape
if cvt("The  quick   ""   ""  brown    fox",16+256)<>"The quick ""   "" brown fox" then escape
if cvt($090909$+"tab"+$090909$+"   space   """+$090909$+"""",16+256)<>$09$+"tab"+$09$+" space """+$090909$+"""" then escape
rem ' 32 = Convert lowercase characters to uppercase.
if cvt("The quick brown fox",32)<>"THE QUICK BROWN FOX" then escape
if cvt("The quick brown fox",32+256)<>"THE QUICK BROWN FOX" then escape
if cvt("The ""very"" quick brown fox",32+256)<>"THE ""very"" QUICK BROWN FOX" then escape
rem ' 64 = Convert "[" and "]" to "(" and ")" respectively.
if cvt("a[5]",64)<>"a(5)" then escape
if cvt("a(5]",64)<>"a(5)" then escape
if cvt("a[5]",64+256)<>"a(5)" then escape
if cvt("a(5]",64+256)<>"a(5)" then escape
if cvt("a[5]""b[5]""",64+256)<>"a(5)""b[5]""" then escape
if cvt("a(5]""b(5]""",64+256)<>"a(5)""b(5]""" then escape
rem ' 128 = Remove all trailing spaces and tabs (option 256 is ignored).
if cvt($09$+"  remove trailing   "+$090909$,128)<>$09$+"  remove trailing" then escape
rem ' 256 = Don't alter characters within double quotes.
if cvt("xyzzy",256)<>"xyzzy" then escape
if cvt($000a8a$,256)<>$000a8a$ then escape
rem ' 512 = Swap bytes in every 2-byte pair (option 256 is ignored)
rem ' For example, $01020304$ becomes $02010403$.
if cvt($01020304$,512)<>$02010403$ then escape
if cvt($010203$,512)<>$020103$ then escape
if cvt("abcde",512)<>"badce" then escape
if cvt($01020304$,512+256)<>$02010403$ then escape
if cvt($010203$,512+256)<>$020103$ then escape
if cvt("abcde",512+256)<>"badce" then escape
rem ' 1024 = Remove all characters that are not spaces, alphabetic
rem ' (upper and lowercase), or numerics.
rem ' 256 = Don't alter characters within double quotes.
if cvt("!!!only-Alpha_Numeric9"+$0a$+" and spaces",1024)<>"onlyAlphaNumeric9 and spaces" then escape
if cvt("!!!only-Alpha_Numeric9"+$0a$+" and spaces",1024+256)<>"onlyAlphaNumeric9 and spaces" then escape
if cvt("!!!only-Alpha_Numeric9"+"""*"""+$0a$+" and spaces",1024+256)<>"onlyAlphaNumeric9""*"" and spaces" then escape
if CVT("x""a-b""y",1024+256)<>"x""a-b""y" then escape
rem ' 2048 = Same as option-value=1, but do not alter the field separator 
rem ' for data records (default field separator is usually $8A$).
rem ' *** Note BBj currently implements CVT(1) and CVT(2048) identically ***
if cvt($00$,2048)<>$00$ then escape
if cvt($8a$,2048)<>$0a$ then escape
if cvt($00$,2048+256)<>$00$ then escape
if cvt($8a$,2048+256)<>$0a$ then escape
if cvt($00$+""""+$ff$+"""",2048+256)<>$00$+""""+$ff$+"""" then escape
if cvt($8a$+""""+$ff$+"""",2048+256)<>$0a$+""""+$ff$+"""" then escape
rem ' 4096 = Convert uppercase characters to lowercase. 
rem ' This has priority over option-value 32 (because it's applied later).
if cvt("The quick brown fox",4096)<>"the quick brown fox" then escape
if cvt("The quick brown fox",4096+32)<>"the quick brown fox" then escape
if cvt("The quick brown fox",4096+256)<>"the quick brown fox" then escape
if cvt("The quick brown fox",4096+32+256)<>"the quick brown fox" then escape
if cvt("The ""VERY"" quick brown fox",4096+256)<>"the ""VERY"" quick brown fox" then escape
if cvt("The quick ""LIKE BUNNY"" brown fox",4096+32+256)<>"the quick ""LIKE BUNNY"" brown fox" then escape
rem ' 8192 = Converts the entire string into its mirror image. 
rem ' For example: "ABCD" becomes "DCBA".
rem '  When combined with other options, this is always performed first.
if cvt("ABCD",8192)<>"DCBA" then escape
if cvt("    ABCD",8192+128)<>"DCBA" then escape
if cvt("ABCD",8192+256)<>"DCBA" then escape
if cvt("    ABCD",8192+128+256)<>"DCBA" then escape
rem ' 16384 = Replaces all unprintable characters with a space
rem ' ($00$ - $1F$ and $7F$ - $FF$).
if cvt("The"+$00$+"quick"+$8a$+"brown"+$80$+"fox",16384)<>"The quick brown fox" then escape
if cvt("The"+$00$+"quick"+$8a$+"brown"+$80$+"fox",16384+256)<>"The quick brown fox" then escape
if cvt("The"+$00$+"quick"""+$00$+""""+$8a$+"brown"+$80$+"fox",16384+256)<>"The quick"""+$00$+""" brown fox" then escape
rem ' 32768 = Removes trailing nulls then trailing LF and CRLF (option 256 is ignored)
if cvt($00$+"trailing nulls"+$0000$,32768)<>$00$+"trailing nulls" then escape
if cvt($00$+"trailing CRLF"+$0d0a0a0000$,32768)<>$00$+"trailing CRLF" then escape
if cvt("    123",8)<>"123" then escape
print "Finished ", pgm(-2)
stop

See Also

CVS() Function - String Data Conversion

Functions - Alphabetical Listing