Skip to content
March 16, 2007 / dshuck

UDF: countHtmlLineBreaks() – return the number of BR tags in a string

Whenever I end up creating some fairly generic little UDF, I usually try to put up here in case some random person somewhere happens to find them useful. Inevitably, I always get *that guy* who gives me grief for doing so and tells me how I should have done it better or how I should have used Xyz() udf instead, but what the heck… here is another one.

I had a need this morning to be able to set the height of a div that contained an unordered list of strings based on the text it contained. I created an algorithm that was basically Ceiling(Len(string)/CharactersPerLine) for each item in the list and then determined the pixel height based on number of lines, but run into an issue where the text could contain tags. I needed a method for counting BR tags, and it should be able to find BR tags with any number of spaces and with or without a closing slash. This is what I came up with.

function countHtmlLineBreaks(String)	{
	var Count = 0;
	while (ReFindNoCase("<\s*br\s*/?\s*>",arguments.String))	{
		Count = Count + 1;
		arguments.String = ReReplaceNoCase(String,"<\s*br\s*/?\s*>","","one");
	}
	return Count;
}

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 591 other followers