|          
left() 函数是 VBScript 的函数,VBScript 将1个汉字看作1个字符,因此用 left()不能得到正确的字符长度。
 我自己编写了如下3个函数,用来取代 len()、left()、right(),希望能解决您的问题。
 
 '--------------------------------------------------------
 'Name:lenX
 'Argument:uStr
 'Return:
 'Description:返回字符串的长度,1个中文字符长度为2
 '--------------------------------------------------------
 
 function lenX(byval uStr)
 dim theLen,x,testuStr
 theLen = 0
 
 for x = 1 to len(uStr)
 testuStr = mid(uStr,x,1)
 if asc(testuStr) < 0 then
 theLen = theLen + 2
 else
 theLen = theLen + 1
 end if
 next
 lenX = theLen
 end function
 
 '--------------------------------------------------------
 'Name:leftX
 'Argument:uStr待处理的字符串
 'uLen要截取的长度
 'Return:
 'Description:返回指定长度的字符串,1个中文字符长度为2
 '--------------------------------------------------------
 
 function leftX(byval uStr,byval uLen)
 dim i,j,uTestStr,theStr
 
 leftX = ""
 j = 0
 
 for i = 1 to len(uStr)
 uTestStr= mid(uStr,i,1)
 theStr= theStr & uTestStr
 if asc(uTestStr) < 0 then
 j = j + 2
 else
 j = j + 1
 end if
 if j >= uLen then exit for
 next
 leftX = theStr
 end function
 
 '--------------------------------------------------------
 'Name:rightX
 'Argument:uStr待处理的字符串
 'uLen要截取的长度
 'Return:
 'Description:返回指定长度的字符串,1个中文字符长度为2
 '--------------------------------------------------------
 
 function rightX(byval uStr,byval uLen)
 dim i,j,uTestStr
 
 rightX = ""
 j = 0
 
 for i = len(uStr) to 1 step -1
 uTestStr = mid(uStr,i,1)
 rightX = rightX & uTestStr
 if asc(uTestStr) < 0 then
 j = j + 2
 else
 j = j + 1
 end if
 if j >= uLen then exit for
 next
 end function
 
 
 |