right ... (string function)

Prev Next

Function Names

right, right include, right last match, right last match include, vright, vright include, vright last match, vright last match include

Description

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

Vectorization: The function names beginning with the prefix v support vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.
Note:For these functions, you need add the prefix letter 'v' in front of the function name. Otherwise the function recognizes a set and attempts to process sets and not strings. See right [set function] for the corresponding set function.

  • right:Returns right part of string until specified position (1 = last character) or first matching string
  • right last match:Returns right part of string until last first matching string
  • right include: Like right, but matching string is included in returned string
  • right last match include: Like right last match, but matching string is included in returned string
  • vright:Like right, vectorization applies if a set with strings is provided instead of a string.
  • vright last match:Like right last match, vectorization applies if a set with strings is provided instead of a string.
  • vright include:Like right include, vectorization applies if a set with strings is provided instead of a string.
  • vright last match include:Like right last match, vectorization applies if a set with strings is provided instead of a string.


Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

2

Parameters

No.TypeDescription
1
input
valid types input string or value(s)

Attention: Numerals and dates are converted to strings prior to processing. If 1st parameter is a set:

  • If the function name starts with the v prefix, the vectorization applies. Provide multiple values in a (nested) set to process all of them at once.
  • Otherwise, please refer to right [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 right (0 = blank string, 1 = last, etc.)
Larger than character count: Full string returned
Negative: Keep number of characters counted from the left (-1 = all except first 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 right ...: Return the right part of the string without the matching pattern.
Function right include ...: Return the right 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 the complete 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
set
Extracted substring(s)

In case vectorization has been applied, then the resulting strings are returned inside a (nested) set.

Examples

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

               echo( right( st[], 0 ), " / ", right( st[], 1 ), " / ", right( st[], -2 ), " / ", right( st[], -1 ) );
               echo( right( st[],99 ), " / ", right( st[],-99) );
               echo;
               echo( right( st[], ' taste' ), " / ", right include( st[], ' taste' ) );
               echo( right( st[], ' ' ), " / ", right last match( st[], ' ' ) );
               echo( right last match include( st[], 'e' ) ); // Last 'e' and exclamation mark
               echo;
               echo( right( st[], 't?ste' ) ); // Softquoted string (no or single quotation marks) - matched
               echo( right( st[], "t?ste" ) ); // Quoted string (double quotation marks) - not matched

Output

 / ! / e taste of the coffee! / he taste of the coffee!
The taste of the coffee! /

of the coffee! /  taste of the coffee!
taste of the coffee! / coffee!
e!

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

See also

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