Hello,
Quick question -- how do I convert or cast an OUString to string and vice versa??
Thanks,
Saleem
[Solved] OUString to String and back
[Solved] OUString to String and back
Last edited by saleem145 on Sun Jul 15, 2012 1:54 pm, edited 1 time in total.
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: OUString to String and back
Working with c++ and OpenOffice, class OUString is your friend. It's often easier to manipulate OUStrings than char *s.saleem145 wrote:Hello,
Quick question -- how do I convert or cast an OUString to string and vice versa??
Thanks,
Saleem
To go back and forth there are a number of tricks.
To make an OUString from a literal there is a macro
Code: Select all
OUString ou = OUString(RTL_CONSTASCII_USTRINGPARAM("literal"));
Code: Select all
char *myName = "Saleem";
OUString OUName = OUString::createFromAscii(myName);
To go the other way, there is an intermediary called oString
Code: Select all
OUString myOUName = OUString(RTL_CONSTASCII_USTRINGPARAM("Saleem"))
OString o = OUStringToOString( myOUName, RTL_TEXTENCODING_ASCII_US );
char *c = o.pData->buffer;
Apache OpenOffice 4.1.1
Windows XP
Windows XP
-
- Posts: 4
- Joined: Thu Jul 19, 2012 3:40 pm
Re: [Solved] OUString to String and back
But how about wide-character strings? How do I get a std::wstring from an OUString?
Ooffice 3.1.1, Linux
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: [Solved] OUString to String and back
I just did a quick test, and I'm not sure I understand it, but it appears you can just do a direct assignment:karsten.burger wrote:But how about wide-character strings? How do I get a std::wstring from an OUString?
Code: Select all
wstring wstr;
OUString ouStr;
ouStr = OUString::createFromAscii("I'm an OUString");
wstr = ouStr;
Code: Select all
wstr = L"Hi there!";
ouStr = wstr.data();
Apache OpenOffice 4.1.1
Windows XP
Windows XP