Building up HTML or other strings using lists...

Building up HTML or other strings using lists...

Hi just another tip.. 

Like other scripting languages there are many ways to concatenate text. One method that get's used a lot in javascript is to use to push string instances into an array and then join the text like this...

myList =["<ul id='myList'>"];
      for(r in data)
      {
            if(this == theOtherThing)
            {
                  myList.push("<li>"+this+"</li>");
            } 
            //end of if
      }
      //end of loop
             var html = myList.join("");
      $(myList).hide().appendTo("body").fadeIn(500); //ok just a little jQuery

Anyways, that's javascript. One thing that really drives me nuts about DS is it's lack of the += operator. So building strings up like this isn't possible...

str = "";

      for each r in myList
       {
            str += "<li>"+r+"</li>";
      }

NOPE! Can't do it you have to do it like this!

      str = "";
      for each r in myList
       {
            str = str + "<li>"+r+"</li>";
      }

Drives me nuts... 

Anyways, here's how I concatenate text now.. 

     str = {}; //OR str = List();
     
      for each r in myList
      {
            myList.add("<li>"+r+"<li>");
      }
      
      html = thisapp.join(myList);

Here's that join function I use... 

string  join(list listToJoin)
{
    str = "";
    for each r in listToJoin
    {
        str = str + r;
    }
    return str;
}

(BTW ZC where are our join and explode methods! You have a toString method but not the same. ).