dsf12313 2010-11-30 12:55
浏览 52
已采纳

在使用Big5编码列出所有文章时仅显示文章的一部分

I'm writing a website with some articles for a Chinese audience. On the page that lists the articles I would like it to list the title and a small proportion of the article. However, the articles are encoded in a mixture of different Big5 encodings. Don't ask me why - that's what I got - so I can't guarantee the number of bytes each character takes to encode.

How can I then trim down the string to show only a small proportion of the article, without chopping off the bytes needed to encode a character?

  • 写回答

1条回答 默认 最新

  • douyanjing0822 2010-11-30 12:58
    关注

    If you're certain that you won't have any characters outside of the BMP then you can convert the text to UCS-2 and then slice on an even boundary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据