dan*_*dan 6 ruby vim fonts asianfonts utf8-decode
使用Ruby,我必须以列式格式输出字符串到终端.像这样的东西:
| row 1 | a string here | etc
| row 2 | another string | etc
Run Code Online (Sandbox Code Playgroud)
我可以使用String#ljust和%s对拉丁文UTF8字符做得很好.
但是当字符是韩文,中文等时出现问题.当有英文行穿插包含韩文等的行时,列不会对齐.
我怎样才能在这里获得列对齐?有没有办法输出相当于固定宽度字体的亚洲字符?如何在Vim中显示和编辑文档?
虽然迟到了,但希望仍然有帮助:在 Ruby 中,您可以使用unicode-display_width gem来检查字符串的 east-asian-width:
\n\nrequire \'unicode/display_width\'\n"\xe2\x9a\x80".display_width #=> 1\n\'\xe4\xb8\x80\'.display_width #=> 2\nRun Code Online (Sandbox Code Playgroud)\n