accelerator-core
Version:
[](https://travis-ci.org/furkleindustries/accelerator-core)
31 lines (28 loc) • 785 B
text/typescript
export class StringBuilder{
private string: string;
constructor(str?: string){
str = (typeof str !== 'undefined') ? str.toString() : '';
this.string = str;
}
get Length(): number{
return this.string.length;
}
public Append(str: string | null){
if (str !== null) {
this.string += str;
}
}
public AppendLine(str?: string){
if (typeof str !== 'undefined') this.Append(str);
this.string += '\n';
}
public AppendFormat(format: string, ...args: any[]){
// taken from http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
this.string += format.replace(/{(\d+)}/g, (match: string, num: number) => {
return typeof args[num] != 'undefined' ? args[num] : match;
});
}
public toString(): string{
return this.string;
}
}