If the text where a replacement is taking place is long (threshold seems to be around 2500 characters), the text gets truncated during the replace operation. This only seems to happen if the replacement text is shorter than the search text.
Description
Description
Details
Details
- Severity
- None
- Resolution
- Open
- Reproducibility
- Always
- Operating System
- Windows 10 x64
- Category
- Modding
Steps To Reproduce
Example:
string test = "Imagine a long string here, for example around 2500 characters [...] [...]"; test.Replace("example", "x"); // `test` is truncated after the replace operation
Additional Information
Workaround:
int SafeReplace(inout string content, string search, string replace) { int count; int searchLen = search.Length(); int replaceLen = replace.Length(); int index = content.IndexOf(search); while (index > -1) { content = content.Substring(0, index) + replace + content.Substring(index + searchLen, content.Length() - index - searchLen); count++; index = content.IndexOfFrom(index + replaceLen, search); } return count; }