[thelist] ASP newbie with needs help asking a question

Maximillian Schwanekamp anaxamaxan at neptunewebworks.com
Thu Mar 18 20:38:38 CST 2004


For what it's worth, a little function to use if you wanted to break at a
word, count backward from your upper character limit:

response.write truncateString(some_string,50)

private function truncateString(str_val,char_limit)
	dim tmpstr,tmparr, i
	if len(str_val)<=char_limit then
		'no need to truncate
		truncateString = str_val
		exit function
	else
		str_val=left(str_val,char_limit)
		tmparr=split(str_val," ")
		if instr(str_val," ")=0 then
			'all one word, just chop it off
			tmpstr = left(str_val,char_limit)
		else
			for i = 0 to ubound(tmparr)
				if len(tmpstr & " " & tmparr(i))>char_limit then
					exit for
				else
					tmpstr = tmpstr & " " & tmparr(i)
				end if
			next
		end if
		tmpstr = tmpstr & "..."
	end if
	truncateString = tmpstr
end function

Good ASP resources:
http://www.devguru/ - Free quick references for VBScript (most Classic ASP
is in VBScript) and ASP (the ASP-specific objects).  You can buy
downloadable versions that are invaluable for, er, quick referencing...
http://www.4guysfromrolla.com - you'll find links to zillions of other ASP
resources from there.

Maximillian Von Schwanekamp




More information about the thelist mailing list