Thanks Yves for the reply. <br>The link provided by you is very helpful.<br><br>Thank you very much.<br><br>Regards,<br>Rajendra<br><br><div class="gmail_quote">On Thu, Mar 22, 2012 at 7:53 PM, Yves Parès <span dir="ltr">&lt;<a href="mailto:yves.pares@gmail.com">yves.pares@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">(Sorry for the double post)<br><br>Forget about ByteString.Char8: it doesn&#39;t handle unicode as it truncates characters.<br>

<br>Going from String to bytestring is easy thanks to the utf8-string (<a href="http://hackage.haskell.org/packages/archive/utf8-string/0.3.7/doc/html/Codec-Binary-UTF8-String.html" target="_blank">http://hackage.haskell.org/packages/archive/utf8-string/0.3.7/doc/html/Codec-Binary-UTF8-String.html</a>) package and pack function from Data.ByteString(.Lazy).<br>



<br>And if you want to convert your String directly to a CString (a Ptr CChar) you better use Foreign.C.String.withCString.<br><br><div class="gmail_quote">Le 22 mars 2012 15:17, Yves Parès <span dir="ltr">&lt;<a href="mailto:yves.pares@gmail.com" target="_blank">yves.pares@gmail.com</a>&gt;</span> a écrit :<div>

<div class="h5"><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This joins the question I asked two days ago here. (See <a href="http://haskell.1045720.n5.nabble.com/Quickest-way-to-pass-Text-to-C-code-td5582223.html" target="_blank">http://haskell.1045720.n5.nabble.com/Quickest-way-to-pass-Text-to-C-code-td5582223.html</a>)<br>




Hope that helps.<br><br><div class="gmail_quote">Le 22 mars 2012 15:10, rajendra prasad <span dir="ltr">&lt;<a href="mailto:rajendradprasad@gmail.com" target="_blank">rajendradprasad@gmail.com</a>&gt;</span> a écrit :<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
Hi,<br><br>I have just started learning Haskell FFI. I am trying to send a string from hastell to a C function. For this, I am required to convert the haskell string to byte string. I have two methods to achieve this task. Both are listed below:<br>






<br>1) import Foreign.C.String<br>    let arg1 = map castCharToCChar &quot;Hello&quot; :: [CChar]<br><br>2) import qualified Data.ByteString.Char8 as B<br>    f = B.pack &quot;Hello&quot;<br><br>I just wanted to know the optimal way to achieve this task. Please suggest the optimal way of doing this. If there is any other way, please share it. <br>






<br>Also, please suggest me any good tutorial to start with Haskell FFI for C/C++.<br><br>Thank you very much.<br><br><br>Regards,<br>Rajendra<br>
<br></div></div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>
</blockquote></div></div></div><br>
</blockquote></div><br>