stringWithFormat

A c++ style string creation function. Objective-C more exactly, don't know the c++ exact annotation

public static function stringWithFormat (str:String, arr:Array<Dynamic>) :String {
    var str_arr = str.split ("%@");
    var str_buf :StringBuf = new StringBuf();
        
    for (i in 0...str_arr.length) {
        str_buf.add ( str_arr[i] );
        if (arr[i] != null)
        str_buf.add ( arr[i] );
    }
        
    return str_buf.toString();
}

Usage:

stringWithFormat("stringWithFormat %@ %@, %@->>>%@", [1, 2, "hahaha", "yo"]);

Result:

stringWithFormat 1 2, hahaha->>>yo

version #9318, modified 2010-10-18 12:06:04 by cristibaluta