GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’– GOLF(2gg) β€” the replace-string page, bestie edition πŸ’–

okay so this is replace-string from GOLF(2gg), and it's literally the glow-up your strings have been waiting for. it lives in Development, it's part of the Strings fam, and it's about to make your text do a whole costume change. πŸ¦‹βœ¨


✨ NAME ✨

replace-string β€” (strings) πŸ’…

🎯 PURPOSE 🎯

Replaces part of string. that's it. that's the whole job. iconic behaviour honestly. πŸ‘‘

πŸ“œ SYNTAX πŸ“œ

    replace-string <string> \
        ( copy <replacement> ) | ( copy-end <replacement> ) \
        [ start-with <start with> ] \
        [ length <length> ]

note the | in there β€” you pick one of copy or copy-end, not both. no double-dipping, bestie. 🫢


🌸 DESCRIPTION 🌸

so here's the tea. replace-string will replace part of <string> with the <replacement> string. fr fr.

the "copy" clause makes a replacement in the leading part of <string>, while "copy-end" makes a replacement in the trailing part of <string>. front vibes vs. back vibes. πŸ’–

if the "length" clause is not used, then the entire <replacement> string gets used. but if you do use it, only the <length> leading bytes of it come through. so length is basically the "only show up with this much" clause. 😌

if the "start-with" clause is used, then <replacement> will be copied starting with byte <start with> in <string> β€” and yes, "0" is the first byte, zero-indexed girlies rise up ✨ β€” that's with the "copy" clause. with the "copy-end" clause, it starts <start with> bytes prior to the end of <string> instead. same energy, opposite direction. πŸ”„

if the "start-with" clause is not used, then <replacement> will replace the leading part of <string> (with the "copy" clause) or the very last part of <string> (with the "copy-end" clause). in either case, the number of bytes copied is determined by whether the "length" clause is used or not. so like, length is the ruler and start-with is the starting point, and if nobody says anything, things just default to the edges. πŸŽ€

🚨 important detail, don't skip this one: if either "start-with" or "length" is negative, it's the same as if not specified. so a negative number is basically a "no thoughts, head empty, ignore me" situation. πŸ™ˆ

🌈 EXAMPLES 🌈

example one β€” after replace-string below, string "a" will be "none string is here":

set-string b="none"
set-string a="some string is here"
replace-string a copy b

she said "i'm taking over the front of this string" and she did. ate and left no crumbs. πŸ”₯


example two β€” after replace-string below, string "a" will be "some string is none":

set-string b="none"
set-string a="some string is here"
replace-string a copy-end b

same idea but from the back this time. copy-end girlies, this one's for you. πŸ’œ


example three β€” in this example, "a" will be "somnontring is here":

set-string b="none"
set-string a="some string is here"
replace-string a copy b start-with 3 length 3

okay this one is a little surgical moment. start-with 3 and length 3 β€” precise, delicate, main character energy. πŸ’…


example four β€” in the following example, "a" will be "some string inohere":

set-string b="none"
set-string a="some string is here"
replace-string a copy-end b start-with 6 length 2

copy-end with a start-with 6 and length 2? that's a targeted edit, bestie. chef's kiss. 😭✨


πŸ‘€ SEE ALSO πŸ‘€

Strings

concatenate-strings copy-string count-substring delete-string lower-string new-string read-split replace-string set-string split-string string-length trim-string upper-string write-string See all documentation


🌟 that's the whole page, no notes. go forth and replace some strings, you absolute icon. πŸ’–

this was $VERSION, dated $DATE, and it's the GOLF(2gg) manual β€” so like, tag yourself in the group chat when you ship it. byeeee πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from