Jump to content

Created some useful string functions (SUP_F4SE required)


Recommended Posts

Hello peeps,
I made some string functions based on functions found in SUP. Basically this will help you keep the number of F4SE extensions down by providing some stuff that is found in other libraries (StringUtil, LL_4Play etc), complementing SUP.
Having said that, BakaUtil (where StringUtil for FO4 resides) and LL_4Play are themselves great extensions with lots of other functions so have a look at those too, imo. Their versions will more than likely be faster than mine because they operate directly on memory addresses with null pointers.
Create a character array from a string
  Reveal hidden contents

Turn a string array into one string
  Reveal hidden contents

Turn a string into an array, split at custom delimiter
  Reveal hidden contents

Turn a hex int (string representation) into a decimal int
  Reveal hidden contents

Turn a decimal Int into a Hex string (questionable use, perhaps for console commands)
  Reveal hidden contents

Note that these functions "need each other". Feedback and improvements appreciated. Will return with more.
Link to comment
Share on other sites

Had some trouble getting ArrayDelim() function to work; Presumably due to me using weird delimiter chars that would need escaping for the regex or whatever.

But I don't understand regex. So I made a new function that works without 'em:

String[] Function StringSplit(String inStr, String delimiter = ",")
    If (inStr == "")
        Return new String[0]
    EndIf
    String[] outStr = new String[1]
    Int i = 0
    Int o = 0
    String curStr = StringFindSubString(inStr, i, i)
    While (curStr != "")
        If (curStr == delimiter)
            outStr.Add("")
            o += 1
        Else
            outStr[o] += curStr
        EndIf 
        i += 1
        curStr = StringFindSubString(inStr, i, i)
    EndWhile
    Return outStr
EndFunction
Link to comment
Share on other sites

  On 11/21/2022 at 7:07 PM, niston said:

Update: SUP F4SE 8.65 has new function to split string into array:

String[] Function SplitStringEx(String StringIN, String delimeter, int iPosStart) global native

It is SO MUCH faster than my function above.

Awesome! Yeah I also ended up having trouble with the one I made. Like you said, if it messes with the regex lookahead pattern it'll behave unpredictably.

 

Removing mine, let's just use Tommi's.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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