<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to export utf-8 strings? in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-export-utf-8-strings/m-p/282521#M2183</link>
    <description>To get a char array with UTF-8 encoding you should use the &lt;B&gt;ToCStr&lt;/B&gt; function of &lt;B&gt;GS::UniString&lt;/B&gt;.&lt;BR /&gt;
&lt;BR /&gt;
For example:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;str.ToCStr (0, MaxUSize, CC_UTF8)).Get ();
&lt;/PRE&gt;

&lt;BR /&gt;
Be careful though, the intermediate CStr object will be disposed after the call, so you have to use the result right in the operation.&lt;BR /&gt;
&lt;BR /&gt;
For example converting to a wstring can be done like this:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;std::wstring ToWString (const GS::UniString&amp;amp; str)
{
	std::wstring_convert&amp;lt;std::codecvt_utf8&amp;lt;wchar_t&amp;gt;, wchar_t&amp;gt; convert;
	return std::wstring (convert.from_bytes (str.ToCStr (0, MaxUSize, CC_UTF8)));
}
&lt;/PRE&gt;</description>
    <pubDate>Sun, 11 Jul 2021 09:26:17 GMT</pubDate>
    <dc:creator>Viktor Kovacs</dc:creator>
    <dc:date>2021-07-11T09:26:17Z</dc:date>
    <item>
      <title>How to export utf-8 strings?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-export-utf-8-strings/m-p/282520#M2182</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Code to test (AC23):&lt;BR /&gt;
&lt;PRE&gt;char orig_utf8[8];
orig_utf8[0] = 0x6b;
orig_utf8[1] = 0xc3;
orig_utf8[2] = 0xa1;
orig_utf8[3] = 0x74;
orig_utf8[4] = 0x79;
orig_utf8[5] = 0xc3;
orig_utf8[6] = 0xba;
orig_utf8[7] = 0x00;

GS::UniString gs_str_in(orig_utf8, CC_UTF8);
ACAPI_WriteReport(gs_str_in, true);  //reports "kátyú", this is the real utf8 string

GS::UChar c1, c2, c3, c4, c5;
c1 = gs_str_in.GetChar(0);
c2 = gs_str_in.GetChar(1);
c3 = gs_str_in.GetChar(2);
c4 = gs_str_in.GetChar(3);
c5 = gs_str_in.GetChar(4);

GS::UniString result("");
result += c1;
result += c2;
result += c3;
result += c4;
result += c5;
ACAPI_WriteReport(result, true);  //reports "kktyy" - why?&lt;/PRE&gt;
Outputs: Why does it report "kktyy"?&lt;BR /&gt;&lt;BR /&gt;How to get utf char array out of a GS::UniString without corruption and memory leak?&lt;BR /&gt;&lt;BR /&gt;Thx,&lt;/DIV&gt;</description>
      <pubDate>Tue, 14 Sep 2021 07:28:31 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-export-utf-8-strings/m-p/282520#M2182</guid>
      <dc:creator>Andor Kocsis</dc:creator>
      <dc:date>2021-09-14T07:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to export utf-8 strings?</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/How-to-export-utf-8-strings/m-p/282521#M2183</link>
      <description>To get a char array with UTF-8 encoding you should use the &lt;B&gt;ToCStr&lt;/B&gt; function of &lt;B&gt;GS::UniString&lt;/B&gt;.&lt;BR /&gt;
&lt;BR /&gt;
For example:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;str.ToCStr (0, MaxUSize, CC_UTF8)).Get ();
&lt;/PRE&gt;

&lt;BR /&gt;
Be careful though, the intermediate CStr object will be disposed after the call, so you have to use the result right in the operation.&lt;BR /&gt;
&lt;BR /&gt;
For example converting to a wstring can be done like this:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;std::wstring ToWString (const GS::UniString&amp;amp; str)
{
	std::wstring_convert&amp;lt;std::codecvt_utf8&amp;lt;wchar_t&amp;gt;, wchar_t&amp;gt; convert;
	return std::wstring (convert.from_bytes (str.ToCStr (0, MaxUSize, CC_UTF8)));
}
&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Jul 2021 09:26:17 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/How-to-export-utf-8-strings/m-p/282521#M2183</guid>
      <dc:creator>Viktor Kovacs</dc:creator>
      <dc:date>2021-07-11T09:26:17Z</dc:date>
    </item>
  </channel>
</rss>

