# How to convert a ruby string into WChar string in ruby?

**URL:** <https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278>\
**Category:** ruby-talk\
**Created:** [25 December 2007 09:23 UTC](https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278 "2007-12-25T09:23:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://rubytalk.org/u/Wu_Nan)\
**Post date:** [25 December 2007 09:23 UTC](https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278/1 "2007-12-25T09:23:13Z")

</div>

Hi,  
I want to use the Win32API, however the API I use need the WChar string as a  
parameter.  
So how can I convert a ruby string into WChar String?

Thanks very much.

---

<div class="post-metadata">

**Author:** ![Konrad\_Meyer](https://avatars.discourse-cdn.com/v4/letter/k/df705f/32.png) [@Konrad\_Meyer](https://rubytalk.org/u/Konrad_Meyer)\
**Post date:** [25 December 2007 16:53 UTC](https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278/2 "2007-12-25T16:53:19Z")

</div>

Quoth Wu Nan:

> Hi,  
> I want to use the Win32API, however the API I use need the WChar string as a  
> parameter.  
> So how can I convert a ruby string into WChar String?
> 
> Thanks very much.

There have been previous posts about this. If you search the archives I'm sure  
you'll find it.

> **···**
>
> --  
> Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)

---

<div class="post-metadata">

**Author:** ![Daniel\_Berger2](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/daniel_berger2/32/2243_2.png) [@Daniel\_Berger2](https://rubytalk.org/u/Daniel_Berger2)\
**Post date:** [26 December 2007 14:36 UTC](https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278/3 "2007-12-26T14:36:49Z")

</div>

require 'windows/unicode'  
include Windows::Unicode

str = multi\_to\_wide(str)

Regards,

Dan

> **···**
>
> On Dec 25, 4:23 am, "Wu Nan" \<i.wunan+rubym...@gmail.com\> wrote:
> 
> > Hi,  
> > I want to use the Win32API, however the API I use need the WChar string as a  
> > parameter.  
> > So how can I convert a ruby string into WChar String?
> > 
> > Thanks very much.

---

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://rubytalk.org/u/Wu_Nan)\
**Post date:** [26 December 2007 03:20 UTC](https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278/4 "2007-12-26T03:20:50Z")

</div>

Hi,  
Thank you for your hint, but I have searched it all around the world with  
Google and also searched the archives.  
Maybe I used a wrong Key words, I found nothing I want.

Could you give me something more information?

Thanks very much.

Nan

> **···**
>
> 2007/12/26, Konrad Meyer \<konrad@tylerc.org\>:
> 
> > Quoth Wu Nan:  
> > \> Hi,  
> > \> I want to use the Win32API, however the API I use need the WChar string  
> > as a  
> > \> parameter.  
> > \> So how can I convert a ruby string into WChar String?  
> > \>  
> > \> Thanks very much.
> > 
> > There have been previous posts about this. If you search the archives I'm  
> > sure  
> > you'll find it.
> > 
> > --  
> > Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)

---

<div class="post-metadata">

**Author:** ![Konrad\_Meyer](https://avatars.discourse-cdn.com/v4/letter/k/df705f/32.png) [@Konrad\_Meyer](https://rubytalk.org/u/Konrad_Meyer)\
**Post date:** [26 December 2007 03:35 UTC](https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278/5 "2007-12-26T03:35:45Z")

</div>

Quoth Wu Nan:

> Hi,  
> Thank you for your hint, but I have searched it all around the world with  
> Google and also searched the archives.  
> Maybe I used a wrong Key words, I found nothing I want.
> 
> Could you give me something more information?
> 
> Thanks very much.
> 
> Nan
> 
> \>  
> \> Quoth Wu Nan:  
> \> \> Hi,  
> \> \> I want to use the Win32API, however the API I use need the WChar string  
> \> as a  
> \> \> parameter.  
> \> \> So how can I convert a ruby string into WChar String?  
> \> \>  
> \> \> Thanks very much.  
> \>  
> \> There have been previous posts about this. If you search the archives I'm  
> \> sure  
> \> you'll find it.  
> \>  
> \> --  
> \> Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)

Maybe this will help you (maybe not):  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/195059](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/195059)

I've been googling for "site:blade.nagaokaut.ac.jp ruby-talk archives windows  
wide character", you can try digging through that too.

Regards,

> **···**
>
> > 2007/12/26, Konrad Meyer \<konrad@tylerc.org\>:
> 
> --  
> Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)

---

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://rubytalk.org/u/Wu_Nan)\
**Post date:** [26 December 2007 04:04 UTC](https://rubytalk.org/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/43278/6 "2007-12-26T04:04:55Z")

</div>

Thank you,  
In fact I have found this post before.  
It indicate the difference between Ruby string and UTF16 string.  
I have tried to find a ruby way (Beatifully and simply), it seems I should  
do it manually now. ☹

Any way, thank you very much.

Nan

> **···**
>
> 2007/12/26, Konrad Meyer \<konrad@tylerc.org\>:
> 
> > Quoth Wu Nan:  
> > \> Hi,  
> > \> Thank you for your hint, but I have searched it all around the world  
> > with  
> > \> Google and also searched the archives.  
> > \> Maybe I used a wrong Key words, I found nothing I want.  
> > \>  
> > \> Could you give me something more information?  
> > \>  
> > \> Thanks very much.  
> > \>  
> > \> Nan  
> > \>  
> > \>  
> > \> 2007/12/26, Konrad Meyer \<konrad@tylerc.org\>:  
> > \> \>  
> > \> \> Quoth Wu Nan:  
> > \> \> \> Hi,  
> > \> \> \> I want to use the Win32API, however the API I use need the WChar  
> > string  
> > \> \> as a  
> > \> \> \> parameter.  
> > \> \> \> So how can I convert a ruby string into WChar String?  
> > \> \> \>  
> > \> \> \> Thanks very much.  
> > \> \>  
> > \> \> There have been previous posts about this. If you search the archives  
> > I'm  
> > \> \> sure  
> > \> \> you'll find it.  
> > \> \>  
> > \> \> --  
> > \> \> Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)
> > 
> > Maybe this will help you (maybe not):  
> > [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/195059](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/195059)
> > 
> > I've been googling for "site:blade.nagaokaut.ac.jp ruby-talk archives  
> > windows  
> > wide character", you can try digging through that too.
> > 
> > Regards,  
> > --  
> > Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)
