Removing All Special Characters


Formatting strings

While handling strings type data many times we get this problem of having special characters like “\n”, “\r”, “\t” or white spaces etc in a string. This small job helps in removing all these special characters.
static void formatString(Args _args)
{
str value = ”   Hello \tSumit         \n Dear”;
    str replace(str _source, str _what, str _with)
{
int found = 0;
str target = _source;
;
do
{
found = strscan(target, _what, found, strlen(target));
if (found != 0)
{
target = strdel(target, found, strlen(_what));
target = strins(target, _with, found);
found += strlen(_with);
}
} while (found != 0);
        return target;
}
;
    info(value);
value = replace(value, ‘\n’, ”);
value = replace(value, ‘\r’, ”);
value = replace(value, ‘\t’, ”);
value = replace(value, ‘ ‘, ”);
    info(value);
}

Leave a comment