Jump to content

Splitting a string, getting a substring, or similar


pra

Recommended Posts

I had a mod idea which would require getting individual chars from an input string.

 

It seems like Skyrim had a StringUtil script which had a substring function, but I can't find anything like that for Fallout4, not even in F4SE. Is there really no way?

 

 

Link to comment
Share on other sites

There is no way that I know of, outside of writing something yourself in F4SE. The problem is that the String class doesn't have any way in Papyrus to look at individual characters or to split a string into parts, though you can concatenate strings together. You can "fake" it by using a String[] and putting only one character into each field for a total of 128 characters, but TextInputMenu doesn't support that.

Edited by Reneer
Link to comment
Share on other sites

I had an idea how to fake it. Comparing strings still works. So appending a letter and repeatedly comparing it to the target string might work. Albeit not really performant.

If I understand what you're saying, no, that won't work. You can't break up whole strings into substrings in any way via Papyrus because you can't read the individual characters of said strings. So you can't do "is string abcde inside string abcdefg."

Edited by Reneer
Link to comment
Share on other sites

i can "is a larger than ab", though. i did that once, you do get alphabetical sorting.

 

so the idea is to build a second string, char by char, and comparing it to the original. this will fail if the original contains any unexpected char, unless i manage to put ALL possible chars into the script.

but, since my goal is to place neon letters, that shouldnt be a problem.

 

however, I'm not sure if I want to do it in such a hacky way...

Link to comment
Share on other sites

I've been thinking about this too, since there was an idea I had when first starting to mod Fallout 4 (that I really shouldn't pursue) that would benefit a LOT from this. If one both wanted to use the script extender and the extender was updated to the point that Skyrim's is (SKSE's StringUtil class, I guess), that would be ideal, but both premises were false when I did my Chicago Typewriter neon-letter placing mod.

What I did for the Typewriter was to fake it by associating the neon letter symbol "alphabet" with my own character set (not EBCDIC), and I just stored the symbol indices (a = 0, etc.). For something more elaborate, you can build a native Papyrus string from that array, but not the other way around.

If I wanted to do it right and over again, I imagine that I would have rolled my own String class and implemented whatever functions I wanted (substring, index access, SOUNDEX, edit distance, you name it). Since arrays are very capacity ham-strung in Papyrus, I would plan to make a LinkedList (of native arrays) primitive storage class tied to actual ingame objects (some hidden physical string in a test cell somewhere, because of the not being able to directly construct objects normally) to store the oversize string content. This kind of write your own data structures approach could be a workable solution, at least until you place the demand on it that you need to get the input from somewhere very specific that supplies a native string primitive (e.g. a text entry UI mod, maybe).

The funky rolling-index comparison thing described may work palatably for cross datatype comparison if your strings are short.

For me, it would just be nice if we could even use the native strings directly without having to play the quest, reference alias, text replacement, message runaround game. Really don't know what they were thinking with leaving out half of standard library string handling.

Link to comment
Share on other sites

Without having downloaded your mod yet, how did you implement text imput, though?

Having an array of ints instead of strings doesn't seem like an issue to me, but, how to even get there?

 

Another thought I just had: does F4Se have anything about reading/writing files? A long time ago, I made a portable home mod for Morrowind, where I stored a string in the savegame by writing it into a file first (using MWSE), and then reading it back as ~100 ints. Then reversing the process to get the string back.

Edited by pra
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...