POSALPHA
POSCHAR
POSDEL
POSDIFF
POSEQUAL
POSINS
POSLOWER
POSRANGE
POSREPL
POSUPPER
Tag Archives: PADR()
String Functions
CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR
CountLeft
CountRight
Descend
Empty
hb_At
hb_RAt
hb_ValToStr
IsAlpha
IsDigit
IsLower
IsUpper
NumAt
NumToken
PadLeft
PadRight
POSALPHA
POSCHAR
POSDEL
POSDIFF
POSEQUAL
POSINS
POSLOWER
POSRANGE
POSREPL
POSUPPER
TokenAt
TokenEnd
TokenExit
TokenInit
TokenLower
TokenNext
TokenNum
TokenSep
TokenUpper
Space()
Space()
Returns a string of blank spaces
Syntax
Space( <nSize> ) --> cString
Arguments
<nSize> The length of the string
Returns
<cString> A string containing blank spaces
Description
This function returns a string consisting of <nSize> blank spaces. If the value of <nSize> is 0, a NULL string (“” ) will be returned.
This function is useful to declare the length of a character memory variable.
Examples
PROCEDURE Main() LOCAL cBigString LOCAL cFirst LOCAL cString := Space( 20 ) // Create an character memory variable // with length 20 ? Len( cString ) // 20 cBigString := Space( 100000 ) // create a memory variable with 100000 // blank spaces ? Len( cBigString ) USE tests NEW cFirst := MakeEmpty( 1 ) ? Len( cFirst ) RETURN FUNCTION MakeEmpty( xField ) LOCAL nRecord LOCAL xRetValue IF ! Empty( Alias() ) nRecord := RecNo() dbGoto( 0 ) IF ValType( xField ) == "C" xField := AScan( dbStruct(), {| aFields | aFields[ 1 ] == Upper( xfield ) } ) ELSE DEFAULT xField TO 0 IF xField < 1 .OR. xField > FCount() xfield := 0 ENDIF ENDIF IF !( xfield == 0 ) xRetvalue := FieldGet( xfield ) ENDIF dbGoto( nrecord ) ENDIF RETURN xRetvalue
Compliance
Clipper
Platforms
All(64K)
Files
Library is core
Seealso
PadC(), PadL(), PadR(), Replicate()
Replicate()
REPLICATE()
Repeats a single character expression
Syntax
REPLICATE( <cString>, <nSize> ) --> cReplicateString
Arguments
<cString> Character string to be replicated
<nSize> Number of times to replicate <cString>
Returns
<cReplicateString> A character expression contain the <cString> fill character.
Description
This function returns a string composed of <nSize> repetitions of <cString>. The length of the character string returned by this function is limited to the memory available.
A value of 0 for <nSize> will return a NULL string.
Examples
? REPLICATE( "a", 10 ) // aaaaaaaaaa ? REPLICATE( "b", 100000 )
Tests
See Examples
Compliance
Clipper
Platforms
All (64K)
Files
Library is rtl
Seealso
SPACE(), PADC(), PADL(), PADR()
PadL()
PADL()
Left-justifies an expression for a given width
Syntax
PADL( <xVal>, <nWidth>, <cFill> ) --> cString
Arguments
<xVal> An number, Character or date to pad
<nWidth> Width of output string
<cFill> Character to fill in the string
Returns
<cString> The left-justifies string of <xVal>
Description
This function takes an date, number, or character expression <xVal> and attempt to left-justify it within a string of a given width expressed as <nWidth>. The default character used to pad left side of <xVal> will be an blank space; however, this character may be explicitly specified the value of <cFill>.
If the length of <xVal> is longer then <nWidth>, this function will truncate the string <xVal> from the leftmost side to the length of <nWidth>.
Examples
? PADL( "Harbour", 20 ) ? PADL( 34.5142, 20 ) ? PADL( Date(), 35 )
Tests
See examples
Compliance
Clipper
Platforms
All
Files
Library is rtl
Seealso
ALLTRIM(), PADC(), PADR()
PadC()
PADC()
Centers an expression for a given width
Syntax
PADC( <xVal>, <nWidth>, <cFill> ) --> cString
Arguments
<xVal> A Number, Character or Date value to pad
<nWidth> Width of output string
<cFill> Character to fill in the string
Returns
<cString> The Center string of <xVal>
Description
This function takes an date, number or character expression <xVal> and attempt to center the expression within a string of a given width expressed as <nWidth>. The default character used to pad either side of <xVal> will be a blank space. This character may be explicitly specified the value of <cFill>.
If the length of <xVal> is longer then <nWidth>, this function will truncate the string <xVal> from the leftmost side to the length of <nWidth>.
Examples
? PADC( "Harbour", 20 ) ? PADC( 34.5142, 20 ) ? PADC( Date(), 35 )
Tests
See Examples
Compliance
Clipper
Platforms
All
Files
Library is rtl
Seealso
ALLTRIM(), PADL(), PADR()
SP_ISVALFILE
ISVALFILE() Short: ------ ISVALFILE() Checks a file name for validity Returns: -------- <lValid> => is file name a valid dos file name Syntax: ------- ISVALFILE(cName,[lCheckDup],[@cMessage]) Description: ------------ Checks the proposed file name in <cName> for adherance to the dos file naming conventions. [lCheckDup] will check for existance of the file if True. Default False. [@cMessage] a string passed by reference. The reason for rejection will be placed in the string. Messages returned are: "File name is empty" "Duplicate file exists" "File name is too long" "Too many periods" "Too many characters after the period" "Too many characters before the period" "Too many characters with no period" "Invalid character: " (character) "Illegal file name" Examples: --------- cFn := space(15) while .t. cMessage := "" @10,10 get cFn read @20,10 say iif(isvalfile(cFn,.t.,@cMessage),"Valid ","Not Valid") @21,10 say padr(cMessage,50) end Source: ------- S_ISVALF.PRG
SP_ADDSPACE
ADDSPACE() Short: ------ ADDSPACE() Pads right of string with spaces Returns: -------- <cPaddedString> => String padded with spaces. Syntax: ------- ADDSPACE(cInString,nPadSpaces) Description: ------------ Pads right side of <cInString> with <nPadSpaces> spaces. Truncates string if <nPadSpaces> is shorter than original string length. Examples: --------- ADDSPACE("GARRY",10) // => "GARRY " Notes: ------- For compatibility. In Clipper 5.x , the function PADR() does the same thing. Source: ------- S_ADDSP.PRG
C5_PAD
PAD() Pad character, date, and numeric values with a fill character ------------------------------------------------------------------------------ Syntax PADL(<exp>, <nLength>, [<cFillChar>]) --> cPaddedString PADC(<exp>, <nLength>, [<cFillChar>]) --> cPaddedString PADR(<exp>, <nLength>, [<cFillChar>]) --> cPaddedString Arguments <exp> is a character, numeric, or date value to be padded with a fill character. <nLength> is the length of the character string to be returned. <cFillChar> is the character with which to pad <exp>. If not specified, the default is a space character. Returns PADC(), PADL(), and PADR() return the result of <exp> as a character string padded with <cFillChar> to a total length of <nLength>. Description PADC(), PADL(), and PADR() are character functions that pad character, date, and numeric values with a fill character to create a new character string of a specified length. PADC() centers <exp> within <nLength> adding fill characters to the left and right sides; PADL() adds fill characters on the left side; and PADR() adds fill characters on the right side. If the length of <exp> exceeds <nLength>, all of the PAD() functions truncate cPaddedString to <nLength>. PADC(), PADL(), and PADR() display variable length strings within a fixed length area. They can be used, for instance, to ensure alignment with consecutive ?? commands. Another use is to display text to a fixed- width screen area assuring that previous text is completely overwritten. PADC(), PADL(), and PADR() are the inverse of the ALLTRIM(), RTRIM(), and LTRIM() functions which trim leading and trailing space from character strings. Examples . This example uses PADR() to format a record number display on a status line filling the allocated space: IF EOF() @ 23, 45 PADR("EOF/" + LTRIM(STR(LASTREC())), 20) ELSEIF BOF() @ 23, 45 PADR("BOF/" + LTRIM(STR(LASTREC())), 20) ELSE @ 23, 45 SAY PADR("Record " + LTRIM(STR(RECNO()) ; + "/" + LTRIM(STR(LASTREC())), 20) ENDIF Files Library is EXTEND.LIB.
See Also: RTRIM()
Uniform Arrays
If a multi-dimension array
– have a fixed number elements in each dimension and
– each column contains the same type of information for each row in array
called “uniform”.
This structure is similar to a table structure.
Built-in functions DBSTRUCT() and DIRECTORY() produces uniform arrays.
Array produced by DBSTRUCT() will have field count in size and the structure of an array is:
Field Name C
Field Type C
Field Width N
Field Dec N
And DIRECTORY() function produces an array with elements as file count and with this structure:
File Name C
File Size N
File Date D
File Time C
File Attributes C
Building, maintaining and using those arrays is simple as possible.
Let’s look at a sample .prg:
-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._ #include "directry.ch" #include "dbstruct.ch" PROCEDURE Main() SET DATE GERM SET CENT ON ? ? "Uniform arrays :" ? ? ? " Directory file list :" ? FileList() ? ? " Table structure list :" ? IF MakUseTable() DispStru() ELSE ? "Couldn't USE or Make th table." ENDIF ? @ MAXROW(), 0 WAIT "EOF UF_Arrays.prg" RETURN // UF_Arrays.Main *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._ PROCEDURE FileList() LOCAL aFList := DIRECTORY( "C:\Harbour\*.*" ) LOCAL a1File FOR EACH a1File IN aFList ? SPACE( 4 ),; PAD( a1File[ F_NAME ], 13 ),; /* File name */ TRAN( a1File[ F_SIZE ], "999,999,999" ),; /* File size */ a1File[ F_DATE ],; /* File date */ a1File[ F_TIME ],; /* File time */ a1File[ F_ATTR ] /* File attribute */ NEXT RETURN // FileList() *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._ FUNCTION MakUseTable() LOCAL cTablName := "CUSTOMER.DBF" LOCAL lRetval, aStru IF FILE( cTablName ) USE (cTablName) ELSE aStru := { { "CUST_ID", "C", 5, 0 },; { "CUST_NAME", "C", 10, 0 },; { "CUST_SNAM", "C", 10, 0 },; { "CUST_FDAT", "D", 8, 0 },; { "CUST_ACTV", "L", 1, 0 },; { "CUST_BLNCE", "N", 11, 2 } } * * 5-th parameter of DBCREATE() is alias - * if not given then WA is open without alias * ^^^^^^^^^^^^^ DBCREATE( cTablName, aStru, , .F., "CUSTOMER" ) ENDIF lRetval := ( ALIAS() == "CUSTOMER" ) RETURN lRetval // MakUseTable() *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._ PROCEDURE DispStru() LOCAL nTotal := 1 IF SELECT() > 0 aStructur := DBSTRUCT() ? SPACE( 4 ), "No: Field Name Type Width Dec" ? SPACE( 4 ), "--- ---------- ---- ----- ---" AEVAL( aStructur, { | aF1, nFNo | ; QOUT( SPACE( 4 ),; // Left Marj PADL( nFNo, 3 ),; // Field No PADR( aF1[ DBS_NAME ], 11 ),; // Field Name PADC( aF1[ DBS_TYPE ], 4 ),; // Field Type PADL( aF1[ DBS_LEN ], 4 ),; // Field Len PADL( aF1[ DBS_DEC ], 3 )),; // Field Dec nTotal += aF1[ 3 ] } ) ? SPACE( 4 ), "--- ---------- ---- ----- ---" ? SPACE( 4 ), "** Total ** ", TRAN( nTotal, "9,999" ) ELSE ? "Current work area is empty" ENDIF RETURN // DispStru() *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._