2008-02-09

Quick sorting in info messages

Sometimes developer face the problem formatting of information messages to user, namely how to sort any items in message especially without duplications. Don't design own sorting algorhytms indeed.

Let's use class Set. The question is toString() method automatically sorts the values and supresses duplicate values.

Following job illustrates how to prepate formatting message using toString() method.

static void JobSetSorting(Args _args)
{
    str         out;
    set         is = new set (types::Real);
    ;

    is.add(0.5);
    is.add(1.25);
    is.add(1.0);
    is.add(3.0);
    is.add(0.5);

    out = is.toString();

    out = strReplace(out,"{", "");
    out = strReplace(out,"}", "");
    //out = strReplace(out,",", "/");

    box::info("In fact: "+out);
}
Copyright © 2008 Ruslan Goncharov

No comments: