You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@openoffice.apache.org by "K.Misha" <mi...@4k.com.ua> on 2013/09/24 17:44:05 UTC
convert rtl::OUString to char *
Hi!
I habe this code:
Reference < XTextDocument > xTextDocument (xWriterComponent,UNO_QUERY);
Reference< XText > xText = xTextDocument->getText();
How can i convert xTextDocument->getText() to char * ?
I used to convert it like this:
int nLenOfAnsiChar = WideCharToMultiByte(CP_OEMCP, NULL,
xText->getString().pData->buffer, -1, NULL, 0, NULL, NULL );
char * str = new char(nLenOfAnsiChar);
WideCharToMultiByte(CP_OEMCP, NULL, xText->getString().pData->buffer,
nLenOfAnsiChar, str, nLenOfAnsiChar, NULL, NULL );
I converted it from unicode to ansi. But when i'm doing it in writer - i
have broken data. I think data here is in ANSI.
Thanks!
Re: convert rtl::OUString to char *
Posted by jg <jg...@jgoettgens.de>.
WideCharToMultiByte() indicates that you are working on Windows. At first you need to convert to
UTF16 (from UTF8), and then from UTF16 to the desired code page.
Have a look at http://code.msdn.microsoft.com/C-UTF-8-Conversion-Helpers-22c0a664 .
jg
Re: convert rtl::OUString to char *
Posted by Ariel Constenla-Haile <ar...@apache.org>.
Hi,
On Tue, Sep 24, 2013 at 06:44:05PM +0300, K.Misha wrote:
> Hi!
>
>
>
> I habe this code:
>
>
>
> Reference < XTextDocument > xTextDocument (xWriterComponent,UNO_QUERY);
>
> Reference< XText > xText = xTextDocument->getText();
>
>
>
> How can i convert xTextDocument->getText() to char * ?
First, the css.text.XText is not a string, use XTextRange::getString()
to get the rtl::OUString.
Then, convert the OUString to an OString and then use OString::getStr()
Reference< XText > xText = xTextDocument->getText();
const rtl::OUString uText = xText->getString();
const rtl::OString sText = rtl::OUStringToOString( sText, RTL_TEXTENCODING_UTF8 );
const char *pzstr = sText.getStr();
Regards
--
Ariel Constenla-Haile
La Plata, Argentina
Re: convert rtl::OUString to char *
Posted by jg <we...@jgoettgens.de>.
WideCharToMultiByte() indicates that you are working on Windows. At first you need to convert to UTF16 (from UTF8), and then from UTF16 to the desired code page.
Have a look at http://code.msdn.microsoft.com/C-UTF-8-Conversion-Helpers-22c0a664 .
jg
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org