List operations for String


I think a welcome addition would be the inclusion of methods designed to manipulate Strings to the Core (or an additional String-focussed) overlay

Examples (I’m bad at naming methods):

"Test".set(0 b)            // = "Best"  (Set a character to the given character)
"Hello1234".numonly        // = "1234"  (Only returns the numbers found in the string)
"Hello...".letonly         // = "Hello" (Only returns the letters found in the string)
"Hello there".range(0 4)   // = "Hello" (Returns the charcters between the given indices)
"Hello".rev                // = "elloH" (Reverses the string)
"Hhello".rem(1)            // = "Hello" (Removes a character)
"Hello there".remr(5 10)   // = "Hello" (Removes all characters between the given indices)
"Hello".fcase(0)           // = "hello" (Flips the case of a single character)
"Hello".fcases             // = "hELLO" (Flips the case of every character)
"Hello".first              // = "H"     (Gets the first character)
"Hello".last               // = "o"     (Gets the last character)
"Hello".case?              // = True    (Uppercase = true, lowercase = false)
"Hello".nup                // = 1       (Returns the number of uppercase characters)
"Hello".nlow               // = 4       (Returns the number of lowercase characters)

Here are some I created for reference (method names may be different): (13.0 KB)

Included are some List methods as well, the String methods depend on some of them

These all work by creating a character array from the string, using List methods on the array and then recombining the array into a string. This effectively allows the use of List methods on Strings, which can then be used to modify or get information from a string

This same principle can be used with any class that can be converted to and from the String Class, this includes, Reals and Integers. Simply convert the Real/Integer to a String, use the provided methods, and convert the resulting string back to Real/Integer
You could use it to create methods like this          // = 1  (Get the number at the given position in the Integer)
9990.set(3 9)       // = 9999 (Sets the number at the given index to the provided Integer value)


There is a bit of philosophy in the reason why the Core String class is so simple. :thinking:

In general, a high performing game should stay away from string manipulation like the plague. We’ve done years and years of optimization on game titles and poor gameplay performance can often be traced down to heavy use of strings at scale. :video_game: :space_invader:

There are many uses for strings outside of games, though SkookumScript’s target use is games and its Core String class is very simple due to this goal. The idea is to prefer Symbol or perhaps Name (in the case of :ue4:) for better performance.

The C++ String class that the SkookumScript String is based on is actually quite sophisticated and we could easily bind more of the C++ methods to :sk:. I love strings and the SkookumScript parser uses our C++ AString class extensively. :nerd_face:

In many circumstances, performance is fine and heavy use of strings isn’t really an issue. In other cases such as working with the web and web page generation, the use of strings can be critical.

We’d be all for a separate more sophisticated string overlay. What you’ve done in your supplied scripts is great!

Our plan is eventually to create a healthy SkookumScript overlay ecosystem that makes it easy for people to create and trade various overlays. We plan create sophisticated overlays and add them to the ecosystem too.