deltreey

nwscript SplitString

Oct 14th, 2023 (edited)
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | Gaming | 0 0
  1. json SplitString(string fullstring, string substring)
  2. {
  3.     json result = JsonArray();
  4.  
  5.     int index = FindSubString(fullstring, substring);
  6.     while (index > -1)
  7.     {
  8.         result = JsonArrayInsert(result, JsonString(GetSubString(fullstring, 0, index)));
  9.         // if this is too high, it's ok, it just goes to the end of the string
  10.         int stringLength = GetStringLength(fullstring);
  11.         fullstring = GetSubString(fullstring, index + GetStringLength(substring), stringLength);
  12.         index = FindSubString(fullstring, substring);
  13.     }
  14.     result = JsonArrayInsert(result, JsonString(fullstring)); // include all to the end of the string
  15.  
  16.     return result;
  17. }
Tags: NWN:EE
Advertisement