left ... (string function)

Prev Next

Function Names

left, left include, left last match, left last match include

Description

This function extracts a left part of the string either with a character position number or a matching pattern.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

2

Parameters

No.TypeDescription
1
input
valid types input string or value

Attention: If 1st parameter is a parameter set, please refer to left [parameter set function] instead. Values of types other than string will be converted to strings first.

2
input
numeral character position

Positive: Keep number of characters counted from the left (0 = blank string, 1 = 1st character, etc.)
Larger than character count: Full string returned
Negative: Keep number of characters counted from the right (-1 = all except last character)

Smaller than minus character count: Empty string returned
Zero: Empty string returned

The function name ending '... include' will be ignored. Using the function name part '... last match ...' will assert an error.

Alt. 2
input
string matching pattern

Function left ...: Return the left part of the string without the matching pattern.
Function left include ...: Return the left part of the string including the matching pattern.
Function name ending ... last match: Looks for the last matching pattern in the string and not the first one.
Empty strings will be interpreted as positive match before the 1st character and this function returns empty strings.

Matching patterns are case-sensitive.
Attention: The matching pattern parameter distinguishes between strings and softquoted strings.
In softquoted strings, following wildcard symbols act as placeholders: '?' for any character, '#' for any digit and '^' for any letter.

Return value

TypeDescription
string Extracted substring

Examples

      st[] = "The taste of the coffee!";

      echo( left( st[], 0 ), " / ", left( st[], 1 ), " / ", left( st[], -2 ), " / ", left( st[], -1 ) );
      echo( left( st[],99 ), " / ", left( st[],-99) );
      echo;
      echo( left( st[], ' taste' ), " / ", left include( st[], ' taste' ) );
      echo( left( st[], ' ' ), " / ", left last match( st[], ' ' ) );
      echo( left last match include( st[], 'e' ) ); // Strips exclamation mark only
      echo;
      echo( left( st[], 'c^ffee' ) ); // Softquoted string (no or single quotation marks) - matched
      echo( left( st[], "c^ffee" ) ); // Quoted string     (double quotation marks) - not matched

Output

 / T / The taste of the coffe / The taste of the coffee
The taste of the coffee! /

The / The taste
The / The taste of the
The taste of the coffee

The taste of the
The taste of the coffee!
Try it yourself: Open LIB_Function_left.b4p in B4P_Examples.zip. Decompress before use.

See also

right [string function]
middle [string function]
outside [string function]
left [parameter set function]