Getting Out of Table Hell

I’ve needed to type more tr’s and td’s then I would like too write. My way around this was to make this stupid hack. Anyway even if a hack is stupid, they can be useful.

Here is a function I made in Java just because I had eclipse up and running.

public String tableBuilder(int row, int col){
	StringBuilder str = new StringBuilder("<table>");
	for(int r = 0; r < row; r++){
		str.append("<tr>");
			
		for(int c = 0; c < col; c++)
			str.append("<td></td>");
			
		str.append("</tr>");
	}
	str.append("</table>");
	return str.toString();
}

Making an HTML skeleton table with two rows and two columns can be down with like this.

System.out.print( tableBuilder(2,2) );
// Sample Output:
// <table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>

Since I’m lazy then just copied and paste my new HTML string into my code and filled in the table td’s

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s