Classic ASP
문자열 바이트로 자르기
NJHouse
2014. 8. 11. 08:32
<script language="vbscript" runat="server">
Function nLeft( str, strcut )
Dim bytesize
Dim nLeft_count
bytesize = 0
for nLeft_count = 1 to len( str )
if asc(mid( str, nLeft_count, 1 ) > 0 then '한글값은 0보다 작다
bytesize = bytesize + 1 '한글이 아닌경우 1Byte
else
bytesize = bytesize + 2 '한글이 경우 2Byte
end if
if strcut >= bytesize then nLeft = nLeft & mid( str, nLeft_count, 1 )
'자르고 싶은 길이 Byte만큼
next
if len( str ) > len( nLeft ) then nLeft = left( nLeft, len(nLeft) - 2 ) & "..."
'문자열이 짤렸을 경우 뒤에 ...을 붙여줌
End Function
</script>
반응형