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);
}
Advertisements

One thought on “Formatting strings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s