개발人

문자열 바이트로 자르기 본문

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>


반응형

'Classic ASP' 카테고리의 다른 글

유용한 함수들  (0) 2015.05.23
Response Object  (0) 2014.08.31
global.asa  (0) 2014.08.11
cmd 객체  (0) 2014.08.11
키를 구하는 소스  (0) 2014.08.11
Comments