I have a string that could be either an english word or a single CJK character. I am guaranteed that this string is in UTF-8 encoding. I am working inside of a perl script.
Th开发者_JAVA百科e higher level problem is I have an array of strings like the one described above. I am doing a join " " @array. I want to know to not add the space when its CJK.
So for CJK I will just do join "" @array.
I have looked around but can't find this exact question.
Thanks.
You could use the regular expression \p{InCJK_Unified_Ideographs}
. This is a Unicode Block (as opposed to Unicode Scripts, which are also supported by Perl, but don't seem to match your problem description).
There are some other candidate blocks, like the Extension A and the Radicals Supplement. Here's a full list.
精彩评论