How to determine whether the content of a string is a double-byte character?

S1 = "the sun is setting along the mountains, and the Yellow River flows eastward toward the sea. if you want to see the scenery of thousands of miles, please climb another tall building."
S2 ="If we don"t have the guts to try anything, what"s the meaning of life?"
S3 = "dangerous buildings are hundreds of feet high, reaching out to pick stars, do not dare to speak loudly, for fear of startling the heavenly people."

< hr >

determine whether the content of the string is in Chinese?

import re

p = re.compile("[\u4e00-\u9fa5]")
s1 = ""
s2 = "If we don"t have the guts to try anything, what"s the meaning of life?"
s3 = ""

import re

p = re.compile("[^\x00-\xff]")
print("".join(i.group() for i in p.finditer(s1)) == s1)
print("".join(i.group() for i in p.finditer(s2)) == s2)
print("".join(i.group() for i in p.finditer(s3)) == s3)

Gentlemen, is there a better method to determine whether the content of a string is a double-byte character?

Mar.02,2021

judge according to the code segment, check the coding table, it seems to be greater than a certain value, and the last byte is in the same block with it, that is, the double-byte character

.
Menu