微软excel中字符串的UTF 8字节长度 [英] UTF 8 byte length of a string in microsoft excel

查看:66
本文介绍了微软excel中字符串的UTF 8字节长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为字符串长度在 8 到 16 之间且最大字节长度小于 40(UTF8 编码)添加单元格数据验证.

I am trying to add in cell data validation for a string length to be between 8 and 16 and the max byte length less than 40(UTF8 encoding).

我使用 excel 主动支持创建了数据验证:
数据验证(数据选项卡 -> 数据验证(在 excel 2016 mac 中删除重复项和合并之间)),在设置选项卡中,有验证

I created a data validation using the excel active support:
Data validation(data tab -> Data Validation (between Remove Duplicates and Consolidate in excel 2016 mac)), In Settings tab, there is validation

criteria:
Validation Criteria:
Allow: Text Length
Data : between
Min : 8 & Max : 16

虽然上面的验证满足我所有的限制(8

对于其他语言(比如日语),虽然字符串长度是通过物理长度计算的(例如:"こんにちはこんにちはこんにちは",日语中的hellohellohello),UTF8字节值为45字节,这是40字节的违规,认为长度只有15.

Though the above validation satisfies all the restrictions i have(8

For other languages(say Japanese), though the string length is being counted though physical length(Eg : "こんにちはこんにちはこんにちは", hellohellohello in Japanese), the UTF8 byte value is 45 bytes, which is the violation of the 40 bytes, thought the length is only 15.

我在 excel 中找到了LENB"函数,但它给出的值为 30(而不是 45).我认为它基于不同的编码(可能是ansi)

I found "LENB" function in excel, but it is giving the value as 30(instead of 45). I think it is based on different encoding(ansi maybe)

我找到了 UNICODE 函数,它给出了上述案例中第一个字符 (12371) 的 unicode 编号.但是我不知道如何从这个数字中获取字节值(3 个字节是第一个字符(こ)的值).

I found the UNICODE function which gives the unicode number of the first character(12371) in the above case. But i don't see how can i get the byte value from this number(3 bytes is the value for the first character(こ)).

在这方面的任何帮助将不胜感激.

Any help in this regard will be greatly appreciated.

推荐答案

使用 Unicode 值,您可以计算特定的值将占用多少字节.<128 为 1 个字节,否则 <2048 为 2,否则 <65536 为 3,否则为 4.

With the Unicode value, you can compute how many bytes a particular one will take. <128 is 1 byte, else <2048 is 2, else <65536 is 3, else 4.

这篇关于微软excel中字符串的UTF 8字节长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆