string.split: Split a String and Extract Elements

View source: R/string.split.R

string.splitR Documentation

Split a String and Extract Elements

Description

Splits a string based on a separator and returns either a specific position or the last element of the resulting vector.

Usage

string.split(string, sep, position)

Arguments

string

A character vector (or object that can be coerced to character)

sep

The separator to use for splitting the string

position

Numeric value indicating which element to extract after splitting. If not provided or non-numeric, returns the last element

Details

The function first ensures the input is a character vector, then splits it using the provided separator. If a numeric position is specified, it extracts that element from each split result. If no position is specified or the position is non-numeric, it returns the last element of each split result.

Value

A character vector containing the extracted elements

Examples

string.split("hello.world", ".", 1)  # Returns "hello"
string.split("hello.world", ".", 2)  # Returns "world"
string.split("hello.world.test", ".") # Returns "test"


ccamp83/mu documentation built on Nov. 7, 2024, 5:17 p.m.