DXL - Unexpected character output

404 views Asked by At

I'm writing a function to replace substrings (what laguange doesn't have this, grr), and I am getting some strange characters in my ouput. I cannot figure out why.

string replaceSubstring(string input, string targetSubstring, string substitute, bool matchCase)
{
    string result = input
    Buffer b = create
    b = input
    int targetStartPos
    int targetLength

    while (findPlainText(result, targetSubstring, targetStartPos, targetLength, matchCase))
    {
        string prefixStr = b[0:targetStartPos - 1]
        string suffixStr = b[targetStartPos + targetLength:]

        b = prefixStr substitute suffixStr
        result = tempStringOf(b)
    }

    delete b
    return result
}

When running print replaceSubstring("Jake Lewis", "ake", "ack", false), I get an output of �*��*�is. This would appear to be some sort of encoding issue, but I am unclear on how this is happening, or how to fix it.

1

There are 1 answers

0
Twonky On BEST ANSWER

Try using stringOf() instead of tempStringOf(). Your processing is fine, but the result becomes invalid after deleting b.