Val()

Val()

Convert a number from a character type to numeric

Syntax

      Val( <cNumber> ) --> nNumber

Arguments

<cNumber> Any valid character string of numbers.

Returns

<nNumber> The numeric value of <cNumber>

Description

This function converts any number previously defined as an character expression <cNumber> into a numeric expression.

This functions is the oppose of the Str() function.

Examples

      ? Val( "31421" ) // 31421

Compliance

Clipper

Platforms

All

Files

Library is core

Seealso

Str(), Transform()

Upper()

Upper()

Converts a character expression to uppercase format

Syntax

      Upper( <cString> ) --> cUpperString

Arguments

<cString> Any character expression.

Returns

<cUpperString> Uppercased value of <cString>

Description

This function converts all alpha characters in <cString> to upper case values and returns that formatted character expression.

Examples

      ? Upper( "harbour" )       // HARBOUR
      ? Upper( "Harbour" )       // HARBOUR

Compliance

Clipper

Platforms

All

Files

Library is core

Seealso

Lower(), IsUpper(), IsLower()

Trim()

Trim()

Remove trailing spaces from a string.

Syntax

      Trim( <cExpression> )   --> cString

Arguments

<cExpression> Any character expression

Returns

<cString> A formatted string with out any blank spaced.

Description

This function returns the value of <cString> with any trailing blank removed.

This function is identical to RTrim() and the opposite of LTrim(). Together with LTrim(), this function equated to the AllTrim() function.

Note : Characters with ASCII code 9, 10 and 13 always treated as “white spaces”.

Examples

      ? Trim( "HELLO" )     //  "HELLO"
      ? Trim( "" )          //   ""
      ? Trim( "UA   " )     //   "UA"
      ? Trim( "   UA" )     //   "   UA"

Compliance

Clipper

Platforms

All

Files

Library is core

Seealso

RTrim(), LTrim(), AllTrim()

Transform()

Transform()

Formats a value based on a specific picture template.

Syntax

      Transform( <xExpression>,  <cTemplate> )  --> cFormatted

Arguments

<xExpression> Any expression to be formated.

<cTemplate> Character string with picture template

Returns

<cFormatted> Formatted expression in character format

Description

This function returns <xExpression> in the format of the picture expression passed to the function as <cTemplate>.

Their are two components that can make up <cTemplate> : a function string and a template string. Function strings are those functions that globally tell what the format of <xExpression> should be. These functions are represented by a single character precede by the @ symbol.

There are a couple of rules to follow when using function strings and template strings:

– First, a single space must fall between the function template and the template string if they are used in conjunction with one another.

– Second, if both components make up the value of <cTemplate>, the function string must precede the template string. Otherwise, the function string may appear with out the template string and vice versa.

The table below shows the possible function strings available with the Transform() function.

      @B   Left justify the string within the format.
      @C   Issue a CR after format is numbers are positive.
      @D   Put dates in SET DATE format.
      @E   Put dates in BRITISH format.
      @L   Make a zero padded string out of the number.
      @R   Insert non template characters.
      @X   Issue a DB after format is numbers are negative.
      @Z   Display any zero as blank spaces.
      @(   Quotes around negative numbers
      @!   Convert alpha characters to uppercased format.

The second part of <cTemplate> consists of the format string. Each character in the string may be formatted based on using the follow characters as template markers for the string.

      A,N,X,9,#   Any data type
      L           Shows logical as "T" or "F"
      Y           Shows logical as "Y" or "N"
      !           Convert to uppercase
      $           Dollar sing in place of leading spaces in 
                  numeric expression
      *           Asterisks in place of leading spaces in 
                  numeric expression
      ,           Commas position
      .           Decimal point position

Examples

      LOCAL cString := "This is harbour"
      LOCAL nNumber := 9923.34
      LOCAL nNumber1 := -95842.00
      LOCAL lValue := .T.
      LOCAL dDate := Date()
      ? "working with String"
      ? "Current String is",  cString
      ? "All uppercased",  Transform( cString,  "@!" )
      ? "Date is",  ddate
      ? "Date is ",  Transform( ddate,  "@D" )
      ? Transform( nNumber,  "@L 99999999" )  //  "009923.34"
      ? Transform( 0      ,  "@L 9999"     )  //  "0000"

Compliance

The @L function template is a FoxPro/Xbase++ Extension

Platforms

All

Files

Library is core

Seealso

@…SAY, DevOutPict()

SubStr()

SubStr()

Returns a substring from a main string

Syntax

      SubStr( <cString>,  <nStart>,  [<nLen>] ) --> cReturn

Arguments

<cString> Character expression to be parsed

<nStart> Start position

<nLen> Number of characters to return

Returns

<cReturn> Substring of evaluation

Description

This functions returns a character string formed from <cString>, starting at the position of <nStart> and continuing on for a length of <nLen> characters. If <nLen> is not specified, the value will be all remaining characters from the position of <nStart>.

The value of <nStart> may be negative. If it is, the direction of operation is reversed from a default of left-to-right to right-to-left for the number of characters specified in <nStart>. If the number of characters from <nStart> to the end of the string is less than <nLen> the rest are ignored.

Examples

      ? SubStr( "HELLO HARBOUR" ,   7,  4 )      // HARB
      ? SubStr( "HELLO HARBOUR" ,  -3,  3 )      // OUR
      ? SubStr( "HELLO HARBOUR" ,   7    )      // HARBOUR

Compliance

Clipper

Platforms

All(64K)

Files

Library is core

Seealso

Left(), At(), Right()

StrZero()

StrZero()

Convert a numeric expression to a character string, zero padded.

Syntax

      StrZero( <nNumber>,  [<nLength>],  [<nDecimals>] ) --> cNumber

Arguments

<nNumber> is the numeric expression to be converted to a character string.

<nLength> is the length of the character string to return, including decimal digits, decimal point, and sign.

<nDecimals> is the number of decimal places to return.

Returns

StrZero() returns <nNumber> formatted as a character string. If the optional length and decimal arguments are not specified, StrZero() returns the character string according to the following rules:

Results of StrZero() with No Optional Arguments

      Expression               Return Value Length
      -----------------------  -----------------------------------
      Field Variable           Field length plus decimals
      Expressions/constants    Minimum of 10 digits plus decimals
      Val()                    Minimum of 3 digits
      Month()/Day()            3 digits
      Year()                   5 digits
      RecNo()                  7 digits

Description

StrZero() is a numeric conversion function that converts numeric values to character strings. It is commonly used to concatenate numeric values to character strings. StrZero() has applications displaying numbers, creating codes such as part numbers from numeric values, and creating index keys that combine numeric and character data.

StrZero() is like Transform(), which formats numeric values as character strings using a mask instead of length and decimal specifications.

The inverse of StrZero() is Val(), which converts character numbers to numerics.

* If <nLength> is less than the number of whole number digits in <nNumber>, Str() returns asterisks instead of the number.

* If <nLength> is less than the number of decimal digits required for the decimal portion of the returned string, Harbour rounds the number to the available number of decimal places.

* If <nLength> is specified but <nDecimals> is omitted (no decimal places), the return value is rounded to an integer.

The StrZero() function was part of the CA-Cl*pper samples.

Examples

      ? StrZero( 10,  6,  2 ) // "010.00"
      ? StrZero( -10,  8,  2 ) // "-0010.00"

Compliance

Clipper

Files

Library is core

Seealso

Str()

StrTran()

StrTran()

Translate substring value with a main string

Syntax

      StrTran( <cString>,  <cLocString>,  [<cRepString>],  
               [<nPos>], [<nOccurrences>] ) --> cReturn

Arguments

<cString> The main string to search

<cLocString> The string to locate in the main string

<cRepString> The string to replace the <cLocString>

<nPos> The first occurrence to be replaced

<nOccurrences> Number of occurrence to replace

Returns

<cReturn> Formated string

Description

This function searches for any occurrence of <cLocString> in <cString> and replaces it with <cRepString>. If <cRepString> is not specified, a NULL byte will replace <cLocString>.

If <nPos> is used, its value defines the first occurrence to be replaced. The default value is 1. Additionally, if used, the value of <nOccurrences> tell the function how many occurrences of <cLocString> in <cString> are to the replaced. The default of <nOccurrences> is all occurrences.

Examples

      ? StrTran( "Harbour  Power",  "  ",  " " )   // Harbour Power
      // Harbour Power The future  of  xBase
      ? StrTran( "Harbour  Power  The Future  of  xBase",  "  ",  " " ,  ,  2 )

Compliance

Clipper

Platforms

All(64K)

Files

Libraty is rtl

Seealso

SubStr(), At()

Str()

Str()

Convert a numeric expression to a character string.

Syntax

      Str( <nNumber>,  [<nLength>],  [<nDecimals>] ) --> cNumber

Arguments

<nNumber> is the numeric expression to be converted to a character string.

<nLength> is the length of the character string to return, including decimal digits, decimal point, and sign.

<nDecimals> is the number of decimal places to return.

Returns

Str() returns <nNumber> formatted as a character string. If the optional length and decimal arguments are not specified, Str() returns the character string according to the following rules:

Results of Str() with No Optional Arguments

      Expression               Return Value Length
      ------------------------ -----------------------------------
      Field Variable           Field length plus decimals
      Expressions/constants    Minimum of 10 digits plus decimals
      Val()                    Minimum of 3 digits
      Month()/Day()            3 digits
      Year()                   5 digits
      RecNo()                  7 digits

Description

Str() is a numeric conversion function that converts numeric values to character strings. It is commonly used to concatenate numeric values to character strings. Str() has applications displaying numbers, creating codes such as part numbers from numeric values, and creating index keys that combine numeric and character data.

Str() is like Transform(), which formats numeric values as character strings using a mask instead of length and decimal specifications.

The inverse of Str() is Val(), which converts character numbers to numerics.

* If <nLength> is less than the number of whole number digits in <nNumber>, Str() returns asterisks instead of the number.

* If <nLength> is less than the number of decimal digits required for the decimal portion of the returned string, Harbour rounds the number to the available number of decimal places.

* If <nLength> is specified but <nDecimals> is omitted (no decimal places), the return value is rounded to an integer.

Examples

      ? Str( 10,  6,  2 ) // " 10.00"
      ? Str( -10,  8,  2 ) // "  -10.00"

Compliance

Clipper

Files

Library is core

Seealso

StrZero(), Transform(), Val()

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()

RTrim()

RTRIM()

Remove trailing spaces from a string.

Syntax

      RTRIM( <cExpression> ) --> cString

Arguments

<cExpression> Any character expression

Returns

<cString> A formatted string with out any blank spaced.

Description

This function returns the value of <cString> with any trailing blank removed.

This function is identical to RTRIM() and the opposite of LTRIM(). Together with LTRIM(), this function equated to the ALLTRIM() function.

Note : Characters with ASCII code 9, 10 and 13 always treated as “white spaces”.

Examples

      ? RTRIM( "HELLO" )              //  "HELLO"
      ? RTRIM( "" )                   //  ""
      ? RTRIM( "UA   " )              //  "UA"
      ? RTRIM( "   UA" )              //  "   UA"

Tests

      See Examples

Compliance

Clipper

Platforms

All

Files

Library is rtl

Seealso

ALLTRIM(), LTRIM(), TRIM()