string_pos: use negative pos value how it works in substr

This commit is contained in:
phobos2077
2023-07-05 01:47:47 +02:00
parent 664fb84dc5
commit f968dea5e7
3 changed files with 13 additions and 5 deletions
+5 -3
View File
@@ -1095,12 +1095,12 @@
doc: "Takes a string and a seperator, searches the string for all instances of the seperator, and returns a temp array filled with the pieces of the string split at each instance. If you give an empty string as the seperator, the string is split into individual characters. You can use this to search for a substring in a string like this: `strlen(get_array(string_split(haystack, needle), 0))`"
opcode: 0x8235
- name: substr
detail: string substr(string text, start, length)
detail: string substr(string text, int start, int length)
doc: |
Cuts a substring from a string starting at "start" up to "length" characters. The first character position is 0 (zero).
- If start is negative - it indicates starting position from the end of the string (for example `substr("test", -2, 2)` will return last 2 charactes: "st").
- If length is negative - it means so many characters will be omitted from the end of string (example: `substr("test", 0, -2)` will return string without last 2 characters: "te").
- If length is zero - it will return a string from the starting position to the end of the string **New behavior** for sfall 4.2.2/3.8.22
- If length is zero - it will return a string from the starting position to the end of the string. **New behavior** for sfall 4.2.2/3.8.22
opcode: 0x824e
- name: strlen
detail: int strlen(string text)
@@ -1122,7 +1122,9 @@
macro: sfall.h
- name: string_pos_from
detail: string string_pos_from(string haystack, string needle, int pos)
doc: Returns position of a first occurance of a needle string in a haystack string (starting from a given 0-based position), or -1 if not found.
doc: |
Returns position of a first occurance of a needle string in a haystack string (starting from a given 0-based position), or -1 if not found.
- If pos is negative - it indicates starting position from the end of the string, similar to substr().
macro: sfall.h
- name: string_format
detail: string string_format(string format, any val1, any val2, ...)