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

**URL:** <https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142>\
**Category:** Ruby\
**Created:** [December 25, 2007, 10:23am UTC](https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142 "2007-12-25T10:23:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://www.ruby-forum.com/u/Wu_Nan)\
**Post date:** [December 25, 2007, 10:23am UTC](https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142/1 "2007-12-25T10:23:53Z")

</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:** ![Wu\_Nan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://www.ruby-forum.com/u/Wu_Nan)\
**Post date:** [December 25, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142/2 "2007-12-25T17:53:53Z")

</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.

---

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://www.ruby-forum.com/u/Wu_Nan)\
**Post date:** [December 26, 2007, 4:21am UTC](https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142/3 "2007-12-26T04:21:47Z")

</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 M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://www.ruby-forum.com/u/Wu_Nan)\
**Post date:** [December 26, 2007, 4:36am UTC](https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142/4 "2007-12-26T04:36:24Z")

</div>

Quoth Wu Nan:

> > > Thanks very much.
> > 
> > There have been previous posts about this. If you search the archives I’m  
> > sure  
> > you’ll find it.
> > 
> > –  
> > Konrad M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [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,

---

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://www.ruby-forum.com/u/Wu_Nan)\
**Post date:** [December 26, 2007, 5:05am UTC](https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142/5 "2007-12-26T05:05:39Z")

</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 M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://www.ruby-forum.com/u/Wu_Nan)\
**Post date:** [December 26, 2007, 3:37pm UTC](https://www.ruby-forum.com/t/how-to-convert-a-ruby-string-into-wchar-string-in-ruby/124142/6 "2007-12-26T15:37:36Z")

</div>

On Dec 25, 4:23 am, “Wu Nan” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

require ‘windows/unicode’  
include Windows::Unicode

str = multi\_to\_wide(str)

Regards,

Dan
