Concatenate Strings from a DataRecord

This script is handy when the site you are scraping separates out a lot of pieces of information that you would like to put back together. For example, let's say you were searching for apartments, and the site you are scraping separates out the number of bedrooms, bathrooms, size of garage, number of living/family rooms, etc. You would like to be able to stick all of this information together into one string. To do this you need to concatenate all of the pieces from the session variables or dataRecord together like this:

apartmentDetails = "";

//do some simple logic tests to make sure that the variable has something in it.
if( dataRecord.get("BEDROOMS")!=null ){
    apartmentDetails = apartmentDetails + "Bedrooms: " + dataRecord.get("BEDROOMS").trim() + "|";
}
if( dataRecord.get("BATHROOMS")!=null ){
    apartmentDetails = apartmentDetails + "Bathrooms: " + dataRecord.get("BATHROOMS").trim() + "|";
}
if( dataRecord.get("GARAGE")!=null ){
    apartmentDetails = apartmentDetails + "Garage: " + dataRecord.get("GARAGE").trim() + "|"
}

//for the next example let's just assume that you had something in the session insead of in the dataRecord
if( session.getVariable("ADDRESS")!=null ){
    apartmentDetails = apartmentDetails + "Address: " + session.getVariable("ADDRESS").trim() + "|";
}

//set the concatenated apartment details into a dataRecord Variable.
dataRecord.put ("APARTMENT_DETAILS", apartmentDetails);

While the above code isn't rocket science, hopefully the value of putting multiple strings together can be easy to see. Now pulling them apart again could be a little bit more troubling. :)