MySQL command line formatting with UTF8

前端 未结 2 829
醉梦人生
醉梦人生 2020-11-29 18:12

I have a database table that contains Swedish/Norwegian strings.

When I query some data, I get output like this:

Output with set names latin1;<

2条回答
  •  遥遥无期
    2020-11-29 18:43

    These words "ø ö ä" with utf8 takes 2 bytes, so did you forget use wchar or utf string?

    Here's my test code in python:

    s = ["Kid Interiør","Bwg Homes","If Skadeförsäkring"]
    for w in s:
        print '|',w.ljust(20,' '),'|' 
    

    the result is as the same as your program print out. all I need to do is change the encoding of string s:

    s = [u"Kid Interiør",u"Bwg Homes",u"If Skadeförsäkring"]
    for w in s:
        print '|',w.ljust(20,' '),'|'
    

    the result is

    | Kid Interiør         |
    | Bwg Homes            |
    | If Skadeförsäkring   |
    

    I haven't test in c++, but I suggest you can use wchar, std::wcout.

提交回复
热议问题