Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Convert GS::UChar_t to std::string

Dayiz
Booster

Hello,

 

I'm trying to convert GS::UChar_t to std::string, but i can't get it done.

Usually I use std::string(GS::ValueToString(value).ToCStr()) to convert a Value to string, but if a value is of type GS::UChar_t this method doesn't work.

Could anyone give me a quick work around?

Thanks!

 

Kind Regards

Dayiz

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Oleg
Expert

I am use:

 

std::string CvtAnsi(const GS::UniString& src)
{
	return src.ToCStr(0, MaxUSize, CC_System).Get(); // Системная кодировка
}

std::string CvtUtf8(const GS::UniString& src)
{
	return src.ToCStr(0, MaxUSize, CC_UTF8).Get();
}

 

 

Convert unicode to ansi is not simple stuff, if used any not english language.
The function used System Code page.

View solution in original post

2 REPLIES 2
Solution
Oleg
Expert

I am use:

 

std::string CvtAnsi(const GS::UniString& src)
{
	return src.ToCStr(0, MaxUSize, CC_System).Get(); // Системная кодировка
}

std::string CvtUtf8(const GS::UniString& src)
{
	return src.ToCStr(0, MaxUSize, CC_UTF8).Get();
}

 

 

Convert unicode to ansi is not simple stuff, if used any not english language.
The function used System Code page.

Hello Oleg,

 

Your methods made me notice, that I should just be able to cast GS::Uchar_t to GS::UniString, which is possible and I ended up doing it like that.

 

Thank you very much for your help 🙂

Kind Regards

Dayiz