<?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 Truncate string based on byte in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661092#M1446294</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking for help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a requirement where i need to truncate string based on byte count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As some of chinese or other language char are multibyte and in string i need to truncate a part based on no of byte.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know in normal scenario we do it as STRING +offset(length) but that gives in character mode count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But based on no off byte i have to extract a substring.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope i am clear about the requirement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Digvijay Singh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 28 Feb 2010 05:24:09 GMT</pubDate>
    <dc:creator>former_member227603</dc:creator>
    <dc:date>2010-02-28T05:24:09Z</dc:date>
    <item>
      <title>Truncate string based on byte</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661092#M1446294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking for help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a requirement where i need to truncate string based on byte count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As some of chinese or other language char are multibyte and in string i need to truncate a part based on no of byte.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know in normal scenario we do it as STRING +offset(length) but that gives in character mode count.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But based on no off byte i have to extract a substring.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope i am clear about the requirement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Digvijay Singh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Feb 2010 05:24:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661092#M1446294</guid>
      <dc:creator>former_member227603</dc:creator>
      <dc:date>2010-02-28T05:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Truncate string based on byte</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661093#M1446295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think if you are working in ECC version, which is Unicode, it's the same for you to use the old way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: NI SHILIANG on Feb 28, 2010 9:55 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Feb 2010 08:54:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661093#M1446295</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-02-28T08:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Truncate string based on byte</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661094#M1446296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Digvijay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if I'm missing the simple solution (and if I understand the problem, because usually you actually want to handle characters and &amp;lt;i&amp;gt;not bytes&amp;lt;/i&amp;gt;), but here's a fairly convoluted one for truncating a string at a specific byte count:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  CONSTANTS:
    co_input  TYPE string VALUE 'u7E41u4F53u5B57'.
  DATA:
    l_codepage TYPE cpcodepage,
    l_encoding TYPE abap_encoding,
    l_conv_out TYPE REF TO cl_abap_conv_out_ce,
    l_conv_obj TYPE REF TO cl_abap_conv_obj,
    l_string  TYPE string,
    l_xstring TYPE xstring.

  CALL FUNCTION 'SCP_CODEPAGE_FOR_LANGUAGE'
    EXPORTING
      language = sy-langu
    IMPORTING
      codepage = l_codepage
    EXCEPTIONS
      OTHERS   = 0.

  l_encoding = l_codepage.
  l_conv_out = cl_abap_conv_out_ce=&amp;gt;create( encoding = l_encoding ).
  l_conv_out-&amp;gt;convert( EXPORTING data   = co_input
                       IMPORTING buffer = l_xstring ).

  sy-fdpos = xstrlen( l_xstring ) - 3.
  l_xstring = l_xstring(sy-fdpos).

  CREATE OBJECT l_conv_obj.
  l_conv_obj-&amp;gt;convert( EXPORTING inbuff    = l_xstring
                                 outbufflg = 0
                       IMPORTING outbuff   = l_string ).

  WRITE: / 'Before:', co_input, ';  After:', l_string.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run this example in our system (codepage 4103, which corresponds to utf-16 little endian) I get the following output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before: 繁体字 ;  After: 繁&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The convoluted coding is in my opinion necessary to avoid splitting multi-byte characters in half. So in the example you can see that I take off three bytes, but it actually results in omitting the last two characters (as we basically got one and a half). I'd hope that somebody has a shorter and more elegant solution, let's see...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you'd know that your strings never contain [surrogate pairs|http://unicode.org/faq/utf_bom.html#utf16-2] you'd have it much simpler though, because then you'd know that one character corresponds to exactly two bytes on the application server (since application server always uses UTF16).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, harald&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Mar 2010 08:09:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661094#M1446296</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-01T08:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Truncate string based on byte</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661095#M1446297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I guess you ask the question because you are in a NON-unicode system. As explained in [ABAP documentation - Conversion Table for Source Field Type c|http://help.sap.com/abapdocu_70/en/ABENCONVERSION_TYPE_C.htm], you may call method CL_SCP_LINEBREAK_UTIL=&amp;gt;STRING_SPLIT_AT_POSITION, to be used especially for non-unicode double-byte characters.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Mar 2010 12:45:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/truncate-string-based-on-byte/m-p/6661095#M1446297</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2010-03-01T12:45:44Z</dc:date>
    </item>
  </channel>
</rss>

