asp字符串连接符 asp字符串连接符&、多个字符串相加、字符串拼接类

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

asp字符串连接符 asp字符串连接符&、多个字符串相加、字符串拼接类

路遥人稀   2021-04-21 我要评论

asp中使用&实现字符串的连接

简单字符串连接

response.write "jb51.net"&""

多个字符串连接

<%
gettj="<a href=""https://www.qb5200.com/tools/zhengze.html"" title=""正则表达式30分钟入门教程"" target=""_blank"">正则表达式30分钟入门教程</a>"&vbcrlf
gettj=gettj&"<a href=""https:"" title=""揭开正则表达式的神秘面纱(regexlab出品)"" target=""_blank"">揭开正则表达式的神秘面纱(regexlab出品)</a>"&vbcrlf
gettj=gettj&"<a href=""http://tools.softyun.net/regex/javascript/"" title=""JavaScript正则表达式在线测试工具"" target=""_blank"">JavaScript正则表达式在线测试工具</a>"&vbcrlf
gettj=gettj&"<a href=""https://www.qb5200.com/tools/regexsc.htm"" title=""正则表达式速查表"" target=""_blank"">正则表达式速查表</a>"&vbcrlf
gettj=gettj&"<a href=""https://www.qb5200.com/tools/regex.htm"" title=""常用正则表达式"" target=""_blank"">常用正则表达式</a>"&vbcrlf
response.write gettj
%>

不如js中直接+=省心

ASP - 字符串拼接类

在ASP中,要拼接字符串的时候,第一个用到的绝对是&,后来在某次项目中,我发现在拼接超长字符串的时候,使用&的效率极低。使用join拼接字符串可使效率提升几百倍。

<%
Class appendString
	Private arrIndex, arrUbound, arrList()
	
	Private Sub Class_Initialize()
		‘分配10长度
		redim arrList(10)
		‘当前长度
		arrIndex = 0
		'每次扩展长度
		arrUbound = 10
	End Sub
	
	Private Sub Class_Terminate()
		'释放所有数组,再次使用时,需要重新分配
		Erase arrList
	End Sub
	
	‘设置值并动态扩展长度
	Public Default Sub Add(value)
		arrList(arrIndex) = value
		arrIndex = arrIndex + 1
		if arrIndex > arrUbound then
			arrUbound = arrUbound + 50
			redim preserve arrList(arrUbound)
		end if
	End Sub
	
	'返回字符串
	Public Function getString(splitString)
		redim preserve arrList(arrIndex - 1)
		getString = join(arrList,splitString)
	End Function	

End Class

'调用方法
Set StringClass = New appendString
StringClass.add("我")
StringClass.add("爱")
StringClass.add("编")
StringClass.add("程")
OutputString = StringClass.getString("")		'打印结果是:我爱编程
%>

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们