ASP如何限定中英文混合的文字输出字数?
生活随笔
收集整理的這篇文章主要介紹了
ASP如何限定中英文混合的文字输出字数?
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?1<%
?2'?字符串截取函數(shù),用于信息標(biāo)題?
?3'?strWord需要截取的字符串?
?4'?intByteLength顯示的字節(jié)長度,1個(gè)漢字兩個(gè)字節(jié)?
?5'?intPadDotAmount背截取后尾部補(bǔ)充點(diǎn)的個(gè)數(shù)?
?6'?字符串截取函數(shù),用于信息標(biāo)題?
?7Function?FixString()Function?FixString(ByVal?strWord,?ByVal?intByteLength,?ByVal?intPadDotAmount)?
?8????????If?strWord?>?""?Then?
?9????????????????If?Length(strWord)?<=?intByteLength?Then?
10????????????????????????FixString?=?strWord?
11????????????????Else?
12????????????????????????Dim?i?
13????????????????????????Dim?intLength?
14????????????????????????Dim?strChar?
15????????????????????????Dim?bytChar?
16????????????????????????intLength?=?0?
17????????????????????????For?i?=?1?to?Len(strWord)?
18????????????????????????????????strChar?=?Mid(strWord,?i,?1)?
19????????????????????????????????bytChar?=?Asc(Mid(strWord,?i,?1))?
20????????????????????????????????If?bytChar?<?0?or?bytChar?>?255?Then?
21????????????????????????????????????????intLength?=?intLength?+?2?
22????????????????????????????????Else?
23????????????????????????????????????????intLength?=?intLength?+?1?
24????????????????????????????????End?If?
25????????????????????????????????If?intLength?>?intByteLength?Then?Exit?For?
26????????????????????????????????FixString?=?FixString?&?strChar?
27????????????????????????Next?
28????????????????????????FixString?=?FixString?&?String(intPadDotAmount,?".")?
29????????????????End?If?
30????????Else?
31????????????????FixString?=?""?
32????????End?If?
33End?Function?
34'?計(jì)算字符串長度,1個(gè)漢字為兩個(gè)字節(jié)?
35Function?Length()Function?Length(ByVal?strWord)?
36????????If?strWord?>?""?Then?
37????????????????Dim?i,?bytChar?
38????????????????Length?=?0?
39????????????????For?i?=?1?to?Len(strWord)?
40????????????????????????bytChar?=?Asc(Mid(strWord,?i,?1))?
41????????????????????????If?bytChar?<?0?or?bytChar?>?255?Then?Length?=?Length?+?2?Else?Length?=?Length?+?1?
42????????????????Next?
43????????Else?
44????????????????Length?=?-1?
45????????End?If?
46End?Function
47content=?FixString("測試,.ba我實(shí),<>",10,0)
48response.Write(content)
49%>
?2'?字符串截取函數(shù),用于信息標(biāo)題?
?3'?strWord需要截取的字符串?
?4'?intByteLength顯示的字節(jié)長度,1個(gè)漢字兩個(gè)字節(jié)?
?5'?intPadDotAmount背截取后尾部補(bǔ)充點(diǎn)的個(gè)數(shù)?
?6'?字符串截取函數(shù),用于信息標(biāo)題?
?7Function?FixString()Function?FixString(ByVal?strWord,?ByVal?intByteLength,?ByVal?intPadDotAmount)?
?8????????If?strWord?>?""?Then?
?9????????????????If?Length(strWord)?<=?intByteLength?Then?
10????????????????????????FixString?=?strWord?
11????????????????Else?
12????????????????????????Dim?i?
13????????????????????????Dim?intLength?
14????????????????????????Dim?strChar?
15????????????????????????Dim?bytChar?
16????????????????????????intLength?=?0?
17????????????????????????For?i?=?1?to?Len(strWord)?
18????????????????????????????????strChar?=?Mid(strWord,?i,?1)?
19????????????????????????????????bytChar?=?Asc(Mid(strWord,?i,?1))?
20????????????????????????????????If?bytChar?<?0?or?bytChar?>?255?Then?
21????????????????????????????????????????intLength?=?intLength?+?2?
22????????????????????????????????Else?
23????????????????????????????????????????intLength?=?intLength?+?1?
24????????????????????????????????End?If?
25????????????????????????????????If?intLength?>?intByteLength?Then?Exit?For?
26????????????????????????????????FixString?=?FixString?&?strChar?
27????????????????????????Next?
28????????????????????????FixString?=?FixString?&?String(intPadDotAmount,?".")?
29????????????????End?If?
30????????Else?
31????????????????FixString?=?""?
32????????End?If?
33End?Function?
34'?計(jì)算字符串長度,1個(gè)漢字為兩個(gè)字節(jié)?
35Function?Length()Function?Length(ByVal?strWord)?
36????????If?strWord?>?""?Then?
37????????????????Dim?i,?bytChar?
38????????????????Length?=?0?
39????????????????For?i?=?1?to?Len(strWord)?
40????????????????????????bytChar?=?Asc(Mid(strWord,?i,?1))?
41????????????????????????If?bytChar?<?0?or?bytChar?>?255?Then?Length?=?Length?+?2?Else?Length?=?Length?+?1?
42????????????????Next?
43????????Else?
44????????????????Length?=?-1?
45????????End?If?
46End?Function
47content=?FixString("測試,.ba我實(shí),<>",10,0)
48response.Write(content)
49%>
轉(zhuǎn)載于:https://www.cnblogs.com/zwl12549/archive/2007/08/13/853221.html
總結(jié)
以上是生活随笔為你收集整理的ASP如何限定中英文混合的文字输出字数?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深度学习:图像识别(匹配)方法|室内定位
- 下一篇: python网易云_使用Python实现