ASP如何限定中英文混合的文字输出字数?

 1 None.gif < %
 2 None.gif '  字符串截取函数,用于信息标题 
 3 None.gif'  strWord需要截取的字符串 
 4 None.gif'  intByteLength显示的字节长度,1个汉字两个字节 
 5 None.gif'  intPadDotAmount背截取后尾部补充点的个数 
 6 None.gif'  字符串截取函数,用于信息标题 
 7 ExpandedBlockStart.gifContractedBlock.gif Function FixString() Function FixString(ByVal strWord, ByVal intByteLength, ByVal intPadDotAmount) 
 8InBlock.gif        If strWord > "" Then 
 9InBlock.gif                If Length(strWord) <= intByteLength Then 
10InBlock.gif                        FixString = strWord 
11InBlock.gif                Else 
12InBlock.gif                        Dim i 
13InBlock.gif                        Dim intLength 
14InBlock.gif                        Dim strChar 
15InBlock.gif                        Dim bytChar 
16InBlock.gif                        intLength = 0 
17InBlock.gif                        For i = 1 to Len(strWord) 
18InBlock.gif                                strChar = Mid(strWord, i, 1
19InBlock.gif                                bytChar = Asc(Mid(strWord, i, 1)) 
20InBlock.gif                                If bytChar < 0 or bytChar > 255 Then 
21InBlock.gif                                        intLength = intLength + 2 
22InBlock.gif                                Else 
23InBlock.gif                                        intLength = intLength + 1 
24InBlock.gif                                End If 
25InBlock.gif                                If intLength > intByteLength Then Exit For 
26InBlock.gif                                FixString = FixString & strChar 
27InBlock.gif                        Next 
28InBlock.gif                        FixString = FixString & String(intPadDotAmount, "."
29InBlock.gif                End If 
30InBlock.gif        Else 
31InBlock.gif                FixString = "" 
32InBlock.gif        End If 
33ExpandedBlockEnd.gifEnd Function
 
34 None.gif '  计算字符串长度,1个汉字为两个字节 
35 ExpandedBlockStart.gifContractedBlock.gif Function Length() Function Length(ByVal strWord) 
36InBlock.gif        If strWord > "" Then 
37InBlock.gif                Dim i, bytChar 
38InBlock.gif                Length = 0 
39InBlock.gif                For i = 1 to Len(strWord) 
40InBlock.gif                        bytChar = Asc(Mid(strWord, i, 1)) 
41InBlock.gif                        If bytChar < 0 or bytChar > 255 Then Length = Length + 2 Else Length = Length + 1 
42InBlock.gif                Next 
43InBlock.gif        Else 
44InBlock.gif                Length = -1 
45InBlock.gif        End If 
46ExpandedBlockEnd.gifEnd Function

47 None.gifcontent =  FixString( " 测试,.ba我实,<> " , 10 , 0 )
48 None.gifresponse.Write(content)
49 None.gif% >

转载于:https://www.cnblogs.com/zwl12549/archive/2007/08/13/853221.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值