substr
Substr is a string operation that extracts a contiguous portion of a string and returns it as a new string. It is implemented as a function or method in many programming languages and libraries, often under the name substr or a closely related variant. The operation is fundamental for text processing, parsing, and formatting tasks.
Typical usage and parameters vary by language. A common form is substr(string, start, length), where start identifies
Notable language variants include:
- C++: std::string substr(size_t pos = 0, size_t len = npos) with 0-based indexing; pos is the index of
- PHP: substr(string, int start, int length) allows negative start to count from the end and can omit
- R: substr(string, start, stop) uses 1-based indexing and end-inclusive positions.
- SQL: SUBSTRING or SUBSTR functions in many dialects extract a substring with a start position and
- JavaScript: substr is a legacy form that takes (start, length); modern code often uses substring or
Examples vary by language, but the underlying idea remains the same: select a slice of characters from