2022년 2월 14일 월요일

javascript - StringBuilder

 

String builder for JavaScript

function StringBuilder(value) {
    this.strings = new Array();
    this.append(value);
}
StringBuilder.prototype.append = function(value) {
    if (value) {
        this.strings.push(value);
    }
}
StringBuilder.prototype.clear = function() {
    this.strings.length = 0;
}
StringBuilder.prototype.toString = function() {
    return this.strings.join("");
}
var sb = new StringBuilder();
sb.append("This is");
sb.append("much better looking");
sb.append("than using +=");
// joins the string
var myString = sb.toString();
// Cleans out the string buffer in the StringBuilder.
// This effectively makes it empty in case you did not
// know what cleaning out a buffer in this context
// meant.
sb.clear();
JavaScript

    출처 : https://www.c-sharpcorner.com/blogs/is-there-a-way-to-implement-a-stringbuilder-in-javascript2



    댓글 없음:

    댓글 쓰기

    javascript - SQL 예약어 제거

      <script language="javascript"> //특수문자, 특정문자열(sql예약어) 제거 function checkSearchedWord(obj){ obj.value = obj.value+&quo...