A useful string intercept function (Chinese characters are counted as two characters, English is one character)

Source: Internet
Author: User
  1. '**************************************************
  2. ' Function name: gottopic
  3. ' function: truncated string, Chinese characters one count two characters, English count a character
  4. ' parameter: str----the original string
  5. ' strlen----intercept length
  6. ' Return value: The truncated string
  7. '**************************************************
  8. Function gottopic (ByVal str, ByVal strlen)
  9. If str = "Then"
  10. Gottopic = ""
  11. Exit Function
  12. End If
  13. Dim L, T, C, I, strtemp
  14. str = replace (replace (replace (str, "," ")," "", Chr), ">", ">"), "<", "<")
  15. L = Len (str)
  16. t = 0
  17. strtemp = str
  18. strlen = CLng (strlen)
  19. For i = 1 to L
  20. c = Abs (ASC (in Mid (str, I, 1))
  21. If C > 255 Then
  22. t = t + 2
  23. Else
  24. t = t + 1
  25. End If
  26. If T >= strlen Then
  27. strtemp = left (str, i)
  28. Exit for
  29. End If
  30. Next
  31. If strtemp <> Str Then
  32. strtemp = strtemp & "..."
  33. End If
  34. Gottopic = replace (replace (replace (strtemp, "", ""), Chr, "" ")," > "," > ")," < "," < ")
  35. End Function
  36. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.