Home > Uncategorized > Replace Carriage Returns and New Lines \r \n in Flex for HTML Template

Replace Carriage Returns and New Lines \r \n in Flex for HTML Template

February 24th, 2009

This came up as I was generating and HTML template in Flex. I wanted a new Table Row foreach New Line of a textArea.text

You’ll see that I am replaceing the \r (carriage returns) with HTML table rows and cells. If you are here you are probably  primarily interested in something simple like

private function otherTasks ( text : TextArea ) : String {
//replace "</td></tr><tr><td>” with whatever you want
	var newString:String = text.text.replace(/[\r\n]/g, "</td></tr><tr><td>");
}
private function otherTasks ( text : TextArea ) : String {
	var temp:String = "<tr><td>";
	temp+= text.text.replace(/[\r\n]/g, "</td></tr><tr><td>");
	var str:String = "";
	str+= "<P><table class=\"sample\" width=\"800\"><thead><tr height=13.75>";
	str+="<th>OTHER TASKS NOT IN MAGIC</th>";
	str += "</tr></thead><tbody>";
	str+= temp;
	str+="</tbody></table>";
	return str;
}

Greg Uncategorized

  1. No comments yet.
  1. No trackbacks yet.