自版本18.11后,支持UTF-8
1.字符转Unicode码
tuple_ord ('s', Ord)
dev_clear_window()
dev_disp_text('\'s\'的Unicode码为'+Ord, 'window', 'center', 'center', 'black','box_color', '#00ffffc0')
dev_clear_window()
dev_disp_text('\'一\'的Unicode码为'+Ord, 'window', 'center', 'center', 'black','box_color', '#00ffffc0')
tuple_ord ('凡', Ord)
dev_clear_window()
dev_disp_text('\'凡\'的Unicode码为'+Ord, 'window', 'center', 'center', 'black','box_color', '#00ffffc0')
tuple_ords ('s一凡', Ords)
dev_clear_window()
dev_disp_text(Ords+'转为十六进制为'+Ords$'#X', 'window', 'center', 'center', 'black','box_color', '#00ffffc0')
2.Unicode码转字符
tuple_chr (0x73, Chr)
dev_clear_window()
dev_disp_text('Unicode码0x73对应字符为'+Chr, 'window', 'center', 'center', 'black','box_color', '#00ffffc0')
tuple_chrt ([0x73,0x4E00,0x51E1], Chrts)
dev_clear_window()
dev_disp_text('Unicode码[0x73,0x4E00,0x51E1]对应字符为:'+Chrts, 'window', 'center', 'center', 'black','box_color', '#00ffffc0')
* * From 18.11, HALCON supports UTF-8. dev_open_window(0, 0, 512, 512, 'black', WindowHandle) set_display_font(WindowHandle, 26, 'mono', 'true', 'false') dev_disp_text('自版本18.11后,支持UTF-8', 'window', 0, 0, 'black','box_color', '#00ffffc0') set_display_font(WindowHandle, 16, 'mono', 'true', 'false') tuple_ord ('s', Ord) dev_clear_window() dev_disp_text('\'s\'的Unicode码为'+Ord, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_ord ('一', Ord) dev_clear_window() dev_disp_text('\'一\'的Unicode码为'+Ord, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_ord ('凡', Ord) dev_clear_window() dev_disp_text('\'凡\'的Unicode码为'+Ord, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_ords ('s一凡', Ords) dev_clear_window() dev_disp_text(Ords+'转为十六进制为'+Ords$'#X', 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_chr (0x73, Chr) dev_clear_window() dev_disp_text('Unicode码0x73对应字符为:'+Chr, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_chrt ([0x73,0x4E00,0x51E1], Chrts) dev_clear_window() dev_disp_text('Unicode码[0x73,0x4E00,0x51E1]对应字符为:'+Chrts, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') * * Unicode编码,字符计数 str:='s一凡一凡' tuple_strlen (str, Length) dev_clear_window() dev_disp_text(str+'length为:'+Length, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') SubString := str{1} dev_clear_window() dev_disp_text('SubString := str{1}为:'+SubString, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') SubString2 := str{2:3} dev_clear_window() dev_disp_text('SubString2 := str{2:3}为:'+SubString2, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_split (str, '一', Substrings) dev_clear_window() dev_disp_text('tuple_split (str, \'一\', Substrings)为:'+Substrings, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_str_first_n (str, 2, SubstringFirstN) dev_clear_window() dev_disp_text('tuple_str_first_n (str, 2, SubstringFirstN)为:'+SubstringFirstN, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_str_last_n (str, 1, SubstringLastN) dev_clear_window() dev_disp_text('tuple_str_last_n (str, 1, SubstringLastN)为:'+SubstringLastN, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_str_last_n (str, 2, SubstringLastN) dev_clear_window() dev_disp_text('tuple_str_last_n (str, 2, SubstringLastN)为:'+SubstringLastN, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_strchr (str, '一', PositionStrChr) dev_clear_window() dev_disp_text('tuple_strchr (str, \'一\', PositionStrChr)为:'+PositionStrChr, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_strrchr (str, '一', PositionStrrChr) dev_clear_window() dev_disp_text('tuple_strrchr (str, \'一\', PositionStrrChr)为:'+PositionStrrChr, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_strstr (str, '一凡', PositionStrStr) dev_clear_window() dev_disp_text('tuple_strstr (str, \'一凡\', PositionStrStr)为:'+PositionStrStr, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') tuple_strrstr (str, '一凡', PositionStrrStr) dev_clear_window() dev_disp_text('tuple_strrstr (str, \'一凡\', PositionStrrStr)为:'+PositionStrrStr, 'window', 'center', 'center', 'black','box_color', '#00ffffc0') * * 正则表达式匹配unicode编码字符 tuple_regexp_match (str, '一.', Matches) tuple_regexp_replace (str, '一.', 'Ω', Result) tuple_regexp_select (str, '一.', Selection) tuple_regexp_test (str, '一.', NumMatches) * * 设置字节模式 set_system ('tsp_tuple_string_operator_mode', 'byte') tuple_strlen ('凡', LengthInByte) tuple_ords ('一', BytesOfUnicodeCharacter) * 设置编码模式 set_system ('tsp_tuple_string_operator_mode', 'codepoint')
标签:编码,center,tuple,dev,window,black,str,Unicode,基本操作 From: https://www.cnblogs.com/echo-efun/p/18053894