RaidersClamoring Posted November 20, 2022 Share Posted November 20, 2022 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 stringString[] Function CharArray(String IN) GlobalString[] OUT = new String[0]Int i = 0While (i < StringGetLength(IN))OUT.Add(StringFindSubString(IN, i, i))i += 1EndWhileReturn OUTEndFunction Turn a string array into one stringString Function ConcatToString(String[] IN) GlobalString OUT = ""Int i = 0While (i < IN.Length)OUT += INi += 1EndWhileReturn OUTEndFunction Turn a string into an array, split at custom delimiter Removed. Just use the SUP_F4SE 8.65 version and upward Turn a hex int (string representation) into a decimal intint Function HxDc(String IN) GlobalString[] HXTBL = CharArray("0123456789ABCDEF")String[] INARR = CharArray(IN)Float SUM = 0.0Int i = INARR.LengthInt r = HXTBL.LengthInt a = 0While (i > 0 && a < INARR.Length)If (INARR[i-1] == HXTBL[r-1])SUM = SUM + ((r-1) as float) * Math.pow(16.0, (a as float))i -= 1a += 1r = HXTBL.LengthElser -=1EndifEndWhileReturn SUM as intEndFunction Turn a decimal Int into a Hex string (questionable use, perhaps for console commands)String Function DcHx(Int IN) GlobalString[] HXTBL = CharArray("0123456789ABCDEF")Int Base = 16String[] OUT = new String[0]If (IN < 17)OUT.Add(HXTBL[iN], 1)ElseWhile (IN != 0)OUT.Insert(HXTBL[iN % Base], 0)IN /= BaseEndWhileEndifReturn ConcatToString(OUT)EndFunction Note that these functions "need each other". Feedback and improvements appreciated. Will return with more. Link to comment Share on other sites More sharing options...
Blinxys Posted November 20, 2022 Share Posted November 20, 2022 THAT"S WHAT I"M TALKIN' ABOUT! :woot: +1 Yo, that's just awesomeness in the making... :ninja: Link to comment Share on other sites More sharing options...
RaidersClamoring Posted November 20, 2022 Author Share Posted November 20, 2022 THAT"S WHAT I"M TALKIN' ABOUT! :woot: +1 Yo, that's just awesomeness in the making... :ninja: Thank you blink! Please if you already copied these, remove the DevBreaker stuff in DelimArray()! Some residue from testing... Link to comment Share on other sites More sharing options...
niston Posted November 20, 2022 Share Posted November 20, 2022 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 More sharing options...
niston Posted November 21, 2022 Share Posted November 21, 2022 Update: SUP F4SE 8.68 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. Link to comment Share on other sites More sharing options...
RaidersClamoring Posted November 21, 2022 Author Share Posted November 21, 2022 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 More sharing options...
Recommended Posts