Next: , Previous: String and character literals, Up: Strings and Characters


6.8.4 String words

Words that are used for memory blocks are also useful for strings, so for words that move, copy, compare and search strings, see Memory Blocks. For words that display characters and strings, see Displaying characters and strings.

capscompare ( c-addr1 u1 c-addr2 u2 – n ) gforth-0.7 “capscompare”

Compare two strings lexicographically, based on the values of the bytes in the strings, but comparing ASCII characters case-insensitively, and non-ASCII characters case-sensitively and without locale-specific collation order. If they are equal, n is 0; if the first string is smaller, n is -1; if the first string is larger, n is 1.

str= ( c-addr1 u1 c-addr2 u2 – f  ) gforth-0.6 “str-equals”

str< ( c-addr1 u1 c-addr2 u2 – f  ) gforth-0.6 “str-less-than”

string-prefix? ( c-addr1 u1 c-addr2 u2 – f  ) gforth-0.6 “string-prefix-question”

Is c-addr2 u2 a prefix of c-addr1 u1?

string-suffix? ( c-addr1 u1 c-addr2 u2 – f  ) gforth-1.0 “string-suffix-question”

Is c-addr2 u2 a suffix of c-addr1 u1?

search ( c-addr1 u1 c-addr2 u2 – c-addr3 u3 flag  ) string “search”

Search the string specified by c-addr1, u1 for the string specified by c-addr2, u2. If flag is true: match was found at c-addr3 with u3 characters remaining. If flag is false: no match was found; c-addr3, u3 are equal to c-addr1, u1.

scan ( c-addr1 u1 c – c-addr2 u2 ) gforth-0.2 “scan”

Skip all characters not equal to c. The result starts with c or is empty. Scan is limited to single-byte (ASCII) characters. Use search to search for multi-byte characters.

skip ( c-addr1 u1 c – c-addr2 u2 ) gforth-0.2 “skip”

Skip all characters equal to c. The result starts with the first non-c character, or it is empty. Scan is limited to single-byte (ASCII) characters.

-trailing ( c_addr u1 – c_addr u2  ) string “dash-trailing”

Adjust the string specified by c-addr, u1 to remove all trailing spaces. u2 is the length of the modified string.

/string ( c-addr1 u1 n – c-addr2 u2 ) string “slash-string”

Adjust the string specified by c-addr1, u1 to remove n characters from the start of the string.

safe/string ( c-addr1 u1 n – c-addr2 u2 ) gforth-1.0 “safe-slash-string”

Adjust the string specified by c-addr1, u1 to remove n characters from the start of the string. Unlike /string, safe/string removes at least 0 and at most u1 characters.

delete ( buffer size u –  ) gforth-0.7 “delete”

deletes the first u bytes from a buffer and fills the rest at the end with blanks.

insert ( string length buffer size –  ) gforth-0.7 “insert”

inserts a string at the front of a buffer. The remaining bytes are moved on.