www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - tried to use wstring in my terminal and see what happened.

reply "Cassio Butrico" <cassio_butrico ig.com.br> writes:
Anyone help me...

I am using the version for the windows dmd v 2.066
to last I believe.

tried to use wstring in my terminal and see what happened.

     wstring name;
     write("wstring - write a name: ");
     //readf("%s\n", &name);
     name =  cast(wstring)chomp(readln());
     //name =  to!wstring(chomp(readln()));// with accent runtime
error utf
     writeln("name  length - ",name.length," - ",name);
     string namec = cast(string)name;//
    // string namec = to!string(name);
     writeln("namec length - ",namec.length," - ", namec);
     writeln("you write: ",namec," ok.");

    wstring - write a name: cassio
    name  length - 3 - µàúþì│µ¢®
    namec length - 6 - cassio
    you write: cassio ok.

or this

     wstring name;
     write("wstring - write a name: ");
     readf("%s\n", &name);
     //name =  cast(wstring)chomp(readln());
     //name =  to!wstring(chomp(readln()));// with accent runtime
error utf
     writeln("name  length - ",name.length," - ",name);
     string namec = cast(string)name;//
    // string namec = to!string(name);
     writeln("namec length - ",namec.length," - ", namec);
     writeln("you write: ",namec," ok.");


    wstring - write a name: cassio
    name  length - 6 - cassio
    namec length - 12 - c a s s i o
    you write: c a s s i o  ok.


very strange do not you think?
I tried several times changing conversions to cast. to! ...
question what I'm doing wrong?

sorry English is not my official language.

aguem  pode me ajudar?
estou usando a versão para win do dmd v 2.066 a ultima creio eu.
tentei usar  wstring no meu terminal e veja o que aconteceu.
muito estranho não acha?
tentei varias vezes mudando as conversões de cast para . to! ...
pergunta  o que estou fazendo de errado?
desculpe-me  ingles não e minha lingua oficial.
Aug 29 2014
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Friday, 29 August 2014 at 22:01:58 UTC, Cassio Butrico wrote:
 Anyone help me...

 I am using the version for the windows dmd v 2.066
 to last I believe.

 tried to use wstring in my terminal and see what happened.

     name =  cast(wstring)chomp(readln());
This line is incorrect. You are telling the compiler to interpret an UTF-8 byte stream as if it was UTF-16.
     //name =  to!wstring(chomp(readln()));// with accent runtime
 error utf
This line is correct. If you are getting an UTF exception, that means that your terminal is not configured to use UTF-8. Your accent characters are probably encoded as an ASCII encoding, not UTF-8. I see you're posting from a Windows machine. On Windows, to switch the terminal to UTF-8, type this command first: chcp 65001 You can do this programmatically in your D program using SetConsoleCP and SetConsoleOutputCP. Note, though, that doing so can affect execution of your program from Windows batch files.
Aug 30 2014
parent "Cassio Butrico" <cassio_butrico ig.com.br> writes:
On Sunday, 31 August 2014 at 03:18:57 UTC, Vladimir Panteleev 
wrote:
 On Friday, 29 August 2014 at 22:01:58 UTC, Cassio Butrico wrote:
 Anyone help me...

 I am using the version for the windows dmd v 2.066
 to last I believe.

 tried to use wstring in my terminal and see what happened.

    name =  cast(wstring)chomp(readln());
This line is incorrect. You are telling the compiler to interpret an UTF-8 byte stream as if it was UTF-16.
    //name =  to!wstring(chomp(readln()));// with accent runtime
 error utf
This line is correct. If you are getting an UTF exception, that means that your terminal is not configured to use UTF-8. Your accent characters are probably encoded as an ASCII encoding, not UTF-8. I see you're posting from a Windows machine. On Windows, to switch the terminal to UTF-8, type this command first: chcp 65001 You can do this programmatically in your D program using SetConsoleCP and SetConsoleOutputCP. Note, though, that doing so can affect execution of your program from Windows batch files.
Thank you for answering me so fast, I'm happy. I'll set the output of my terminal, and redo some tests. again thank you for your help. I was creating a way of resolveir this, create a repositoio up. https: //cassio_butrico bitbucket.org/cassio_butrico/dic.git
Aug 30 2014