Convert UTF-8 to UTF-16

How do I convert UTF-8 to UTF-16. I want code to be like this..
public String convert (String string)
     //do something with the String
     return string;
}Thanks in advance..

From Unicode standard:
<quote>
Below code only supports three byte CJKs hex dumps
character string:
public class UTF8toUC16{
public static void main(String[] args){
String utf8 = "e799be";
String bin, binrep, uchex;
String[] bins, uc;
if (args.length > 0){
utf8 = args[0];
if (utf8.charAt(0) != 'e' || utf8.length() !=
6){
System.err.println("This program accepts utf8
hex-string for CJK");
System.exit(1);
bin =
Integer.toBinaryString(Integer.parseInt(utf8, 16));
binrep = "";
for (int i = 0; i < bin.length(); ++i){
binrep += (bin.charAt(i));
if ((i + 1) % 4 == 0 && (i != bin.length() - 1)){
binrep += ' ';
System.out.println(binrep);
bins = binrep.split("\\s");
uc = new String[4];
uc[0] = bins[1];
uc[1] = bins[2].substring(2) + bins[3].substring(0,
2);
uc[2] = bins[3].substring(2) +
bins[4].substring(2);
uc[3] = bins[5];
uchex = "";
for (int i = 0; i < 4; ++i){
System.out.print(uc[i] +" ");
uchex += Integer.toHexString(Integer.parseInt(uc,
2));
System.out.println();
System.out.println(uchex);
System.out.println((char)(Integer.parseInt(uchex,
16)));
thanks! its solved my problem.. thanks :-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Convertion from UTF-16 to UTF-8 in XI

    Hi,
      From Source system (MDM), sometimes data are coming in UTF-16 format in to XI. My target system is R/3 which is UTF-8. Here's the scenario:-
    MDM->MQ Queue-> Local JMS Queue-> XI->R/3
    Here I am using sender JMS Queue adapter to receive the data from Local JMS Queue and using receiver IDOC adapter to send the IDOC into R/3. I am using ABAP mapping for this scenario.
      Since the target system in UTF-8 and the data are coming sometimes in UTF-16, how can I change the format UTF-16 to UTF-8 in sender JMS adapter.
    Please advice.
    Reply with details would be appreciated.
    BR
    Soumya

    Hi Soumya ,
    You can do this in Adapter module in JMS sender adapter .
    obj = inputModuleData.getPrincipalData();
    msg = (Message) obj;
    XMLPayload xmlpayload = msg.getDocument();               
    xmlpayload.getContent()
    convert from UTF 16 to UTF 8 then
    xmlpayload.setContent();
    Hope this works.
    Cheers,
    Reddy

  • How to convert UTF-16 to UTF-8

    data source is 'ъѓъѓ№ѓфчр Фюыр№ 80Ъ                     ', it is Ukraine.
    I want to remove the blank, but no matter which key word in SAP I use, it doesn't work. i checked hexadecimal of the space from the text above , it is 00A0, but actually system only regard 0020 as space. i checked on internet,  the space of the text should be encoded with UTF-16 and system is UTF-8, 00A0 is extended ASCII, so 00A0 can't be seen in SAP system.
    my question is in this situation, how can a remove the space?

    Hi Eric,
    This Document might help u,
    Link: [how to convert UTF-16 to UTF-8|How to convert xml utf 16 to utf 8;
    -Dileep .C

  • Convert file format into UTF-8 while generating text file on FTP server

    Hi Expert,
    I have the requirement to generate text file store it in FTP server and file format should be in UTF-8.
    ABAP Development is completed but text file format generate in ANSI which not acceptable by client.For generating text file and store it on FTP server by using standard function module FTP_R3_TO_SERVER ,but in this function module there is no any parameter option like CODEPAGE for file format conversion. Is there any method or any function module to convert file format to UTF-8 and directly transfer or store it on FTP server.
    <<removed_by_moderator>>
    Thanks ,
    Edited by: Vijay Babu Dudla on Jan 28, 2009 12:48 AM

    I have come across the same issue.  Try calling the FTP_COMMAND function module to make it go into ASCII mode before your FTP the file, like this:
    data: result type table of text with header line.
    call function 'FTP_COMMAND'
        exporting
          handle        = hdl
          command       = 'ascii'
        tables
          data          = result
        exceptions
          tcpip_error   = 1
          command_error = 2
          data_error    = 3.
      call function 'FTP_R3_TO_SERVER'
        exporting
          handle         = hdl
          fname          = docid
          character_mode = 'X'
        tables
          text           = gt_your_table .

  • Dilemma converting arbitrary encoding to UTF-8

    Here's my dilemma: I recently modified our webapp to use UTF-8 encoding across the board, since data with special characters that users added to the content management backend was being displayed incorrectly in ISO-8859-1. It works great for Strings we get from the database, since it uses UTF-8. The problem now is that there are also files that consist of html chunks that get added to pages when they're rendered by the jsps. Those files aren't always UTF-8 encoded, so characters are displaying incorrectly in those parts of the page.
    The problem is that we don't know what encoding the html chunks are, some are ISO-8859-1, some are Windows-1252, etc. There are hundreds of them, and the users use all kinds of programs to generate the files, Frontpage, Dreamweaver, etc. so there's no common encoding used. I'm trying to modify the code that reads those files so it converts the text to UTF-8 for display, but without knowing what encoding the file is in, how can you do the conversion properly? Here's the code I have currently:
            ByteArrayInputStream contentInput = file.getContent();
            // wrap byte stream in UTF-8 character stream
            BufferedReader br = new BufferedReader(new InputStreamReader(contentInput, "UTF-8"));
            StringBuffer outputBuffer = new StringBuffer("");
            do {
                readString = br.readLine();
                outputBuffer.append(readString);
            while (readString != null);We get a ByteArrayInputStream from the third party API, which I wrap in a UTF-8 encoded BufferedReader. The problem is that, for instance, this character '�', when encoded in the file as ISO-8859-1, get's garbled when converted to UTF-8.
    My question is: Is there a way to convert text to UTF-8 without knowing the encoding of the file? I suspect the answer is no, but I'm really hoping it's yes, since the alternative is re-encoding hundreds to thousands of files in the db, then retraining hundreds of users to always save files as UTF-8. (You can't see my brain spasming at the thought of that, but trust me, it is ;P).

    As an update, in case anyone else runs into this same problem:
    I used the SmartEncodingInputStream from uncle_alice's link, and it works just well enough to solve my problem. The only encoding that it guessed correctly was UTF-8. But it guessed windows-1252 for US-ASCII, windows-1252, and ISO-8859-1. Since 1252 is a superset of ascii and 8859, using 1252 decodes all the characters correctly from those encodings. All the content I tested with was decoded correctly, presumably because it all uses one of those four encodings. The one snag I hit was that the SmartEncodingInputStream doesn't reset the InputStream after it reads it, so I have to do it manually after getting the guessed encoding. Here's the code I used:
            // Get the file content
            ByteArrayInputStream contentInput = file.getContent();
            StringBuffer outputBuffer = new StringBuffer("");
            // wrapper around the input stream that guesses the encoding of the stream
            SmartEncodingInputStream smartIS = null;   
            // use a 8k buffer, and a default encoding of windows-1252
            smartIS = new SmartEncodingInputStream(contentInput, SmartEncodingInputStream.BUFFER_LENGTH_8KB,
                    Charset.forName("windows-1252"));
            String charsetName = smartIS.getEncoding().name();      // get the name of the encoding guessed
            contentInput.reset();       // reset the position to the beginning of the stream
            byte[] contentBuffer = new byte[8192];
            int bytesRead = 0;
            while( (bytesRead = contentInput.read(contentBuffer, 0, 8192)) > 0 ) {
                // encode the output with the encoding guessed by the SmartEncodingInputStream
                outputBuffer.append(new String(contentBuffer, 0, bytesRead, charsetName));
            contentInput.close();I left out the try/catch blocks for readability. I get the ByteArrayInputStream from a library call, and end up with the file contents encoded in UTF-8 in outputBuffer.

  • Convert UTF-16 to UTF-8

    Hi
    My source file is UTF-16 and Target file is UTF-8. I am using XSLT mapping . If i m testing in Altova XML  its working fine. But when i am testing the same thing using my scenario its not wroking.
    I have tested this using Test option in ID. If i change the UTF-16 to UTF-8 while testing in ID but if i m trying to change it directly in XML file its not accepting.
    How to change UTF-16 to UTF-8 while XSLT mapping. How to reslove this problem
    Regards
    Sowmya

    Which Adapter you are using?
    If you are using the file adapter then you can use the File adapter property as file.encoding=<codepage>
    you can refer to below link
    http://help.sap.com/saphelp_nw04/helpdata/en/0d/00453c91f37151e10000000a11402f/frameset.htm
    Gaurav Jain

  • Encoding from UTF-16 to UTF-8

    Hi,
    I need to convert from UTF-16 to UTF-8 encoding.
    I receive an CSV file in encoding UTF-16 for our backend system. but our external partner needs the encoding to be UTF-8
    How can I change the encoding ?

    Hello Frank,
    We have used TextCodePageConversionBean to meet such a requirement in one of our scenarios using CSV files.
    http://help.sap.com/saphelp_nw04/helpdata/en/45/da2deb47812e98e10000000a155369/content.htm
    Can you please try this and let us know if this helps?
    Thanks.
    Best Regards,
    Shweta

  • Identify UTF-8 and UTF-16 formats

    hi,
    Clients submit there unicode messages (arabic,telugu etc langs) in hex format then our application accepts that message and process it.
    But there are many tools in the market which will convert the unicode to UTF-8 and UTF-16 formats.
    so i need to idetify whether the message is in
    UTF-8 or
    UTF-16 or
    hex(no problem)
    something like
    isUTF8(String message)
    isUTF16(String message)
    so that i can convert them back to hex and dump it into database.
    regards
    Heral raj

    You can identify whether it is UTF16 or UTF8 by looking at it's BOM (byte order mark). These are first 2 bytes of the stream.
    Check this link http://www.websina.com/bugzero/kb/unicode-bom.html
    I do not think implementation should be a problem
    Thanks
    Gaurav

  • Reverting the Portal Encoding back to UTF-8 from UTF-16

    Hi all
    The portal configuration for encoding is changed to UTF-16 from UTF-8. After the changes the portal logon screen itself is coming with the junk values.
    The changes are made according to the link below.
    <b>File Based Configuration Properties</b>
    http://help.sap.com/saphelp_nw04/helpdata/en/6a/39fb402eb5f76fe10000000a1550b0/content.html
    The changes made are not reflected.
    We can see that the value of the variable(runtime.doubleByteSupport.encoding
    ) is not changed in Visual admin.(Parameter Reporting in the Visual Administrator)
    Can anyone help regarding this isssue...
    Thanks in advance
    Geogi

    Any Help???

  • Can any version of Excel save to a CSV file that is either UTF-8 or UTF-16 encoded (unicode)?

    Are there any versions of Excel (chinese, japanese, russian... 2003, 2007, 2010...) that can save CSV files in Unicode (either UTF-8 or UTF-16)?
    If not, is the only solution to go with tab-delimited files (save as Unicode-text option)?

    Hi Mark,
    I have the same problem. Trying to save my CSV file in UTF8 encoding. After several hours in searching and trying this also in my VSTO Add-In I got nothing. Saving file as Unicode option in Excel creates file as TAB separated. Because I'd like to save the
    file in my Add-In application, the best to do is (for my problem) saving file as unicode tab delimited and then replacing all tabs with commas in the file automatically.
    I don't think there is a direct way to save CSV as unicode in Excel. And I don't understand why.

  • UTF-16 to UTF-8

    Does anyone know of a easy way to go from UTF-16 National character set to UTF-8 ?? I don't have the time to rebuild RAC databases sitting on raw devices.
    Any help would be appreciated.
    Thanks

    NO, there's no relationship between a RAC db and character sets, nor did I say there was. I stated that I don't have the time to recreate it because it is a RAC db on raw devices. It's Oracle 9i, the only version you would have a RAC database sitting on raw devices. I need to go from a national character set of UTF-16 to UTF-8 as I have already stated.

  • How is the largest cde point differs from UTF-8 to UTF-16

    how is the largest cde point differs from UTF-8 to UTF-16
    the largest code point is 10FFFF for both of them then how is differ from the fromat
    thank you,
    Regards,
    Jagrut BharatKumar Shukla

    In this specific case there are no differences for code points storing character data because used character set is the same.
    But what is your Oracle 4 digits version ?
    Are you sure that database character set and national character set are the same ?
    In recent Oracle versions, database character set and national character set are different. For example:
    SQL> select * from nls_database_parameters where parameter like '%SET%';
    PARAMETER                      VALUE
    NLS_CHARACTERSET               AL32UTF8
    NLS_NCHAR_CHARACTERSET         AL16UTF16Edited by: P. Forstmann on 28 sept. 2011 18:51

  • How we represent largest code point in UTF-8 and UTF-16 whats the differenc

    how we represent largest code point in UTF-8 and UTF-16 whats the differenc
    points will be awarded

    There are standards from for CHARACTER encoding.
    See below for a brief description:
    UTF-16 (16-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, capable of encoding the entire Unicode repertoire. The encoding form maps code points (characters) into a sequence of 16-bit words, called code units. For characters in the Basic Multilingual Plane (BMP) the resulting encoding is a single 16-bit word. For characters in the other planes, the encoding will result in a pair of 16-bit words, together called a surrogate pair. All possible code points from U0000 through U10FFFF, except for the surrogate code points UD800–UDFFF, are uniquely mapped by UTF-16 regardless of the code point's current or future character assignment or use.
    UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. It is able to represent any universal character in the Unicode standard, yet the initial encoding of byte codes and character assignments for UTF-8 is consistent with ASCII (requiring little or no change for software that handles ASCII but preserves other values). For these reasons, it is steadily becoming the preferred encoding for e-mail, web pages, and other places where characters are stored or streamed.
    Check this site for details.
    http://unicode.org/.

  • Convert ASCII HttpServletRequest to UTF-8 Correctly (Possible)?

    Hi All, Is it possible to convert a request encoded in ASCII that contained UTF-8 Characters to UTF-8 correctly? I am using ATG Dynamo's Application server and for the life of me, it doesn't seem to let me encode the request in anything but ASCII. Anyone have any suggestions.
    Thanks,
    Rick

    i mean how do i get utf-8 "\ue0d0" from parsing in the string "U+e0d0"?The String object written in the form of "\u0000" has no relation with UTF-8 by itself, but the form is the Unicode escape sequence. The encoding UTF-8 is a way of transforming the String object to a byte array in a specified manner.
    If you have "U+0000" then you can replace 'U' and '+' with '\' and 'u' with a simple code, though the converted form does not work in a program. What should be done depends on what your aim is.

  • How to convert xml utf 16 to utf 8

    Is it possible to convert xml file with UTF16 to UTF8 using ABAP? I am using ECC 6.0
    Appreciated your inputs.

    Hhmm, interesting. I thought it should be straightforward, but it the two solutions I could think of seem a bit convoluted. First way is probably to use the iXML libray, where the starting point is the class CL_IXML. You can find the SAP documentation [here|http://help.sap.com/saphelp_nw04/helpdata/en/86/8280d212d511d5991b00508b6b8b11/frameset.htm].
    Then there's a "manual approach": Use OPEN DATASET to read the UTF-16 file, then modify the XML encoding attribute and save it as UTF-8 file. Not straightforward, because the tempting command option [OPEN DATASET .. LEGACY TEXT MODE CODE PAGE|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_MODE.htm] doesn't work. Per ABAP help:
    For the specification of the code page cp, a character-type data object is expected that must contain - at the time of execution of the statement - the label of a non-Unicode page from the column CPCODEPAGE in the database table TCP00. A Unicode page must not be specified.
    Darn, looks like they expect most Unicode files to be UTF-8. But that might be the reason you want to convert it...
    So use the following steps:
    <ol><li>Open the file as a binary file (only option for UTF-16, seev[here|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_ENCODING.htm]) via [OPEN DATASET file FOR INPUT IN BINARY MODE|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET.htm] and read content into XSTRING using [READ DATASET|http://help.sap.com/abapdocu_70/en/ABAPREAD_DATASET.htm].</li>
    <li>Convert it to a string using utility class [CL_ABAP_CONV_IN_CE|http://help.sap.com/saphelp_nw04/helpdata/en/79/c554afb3dc11d5993800508b6b8b11/frameset.htm], see example [here|http://wiki.sdn.sap.com/wiki/display/Snippets/ABAPCodePage+Conversions].</li>
    <li>Replace the encoding markup for UTF-16 in the XML with a reference to UTF-8.</li>
    <li>Write the XML content back to a file using [OPEN DATASET file|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET.htm] FOR [OUTPUT|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_ACCESS.htm] IN [TEXT MODE|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_MODE.htm] [ENCODING UTF-8|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_ENCODING.htm] and [TRANSFER|http://help.sap.com/abapdocu_70/en/ABAPTRANSFER.htm]</li></ol>
    Maybe somebody has a shorter way...
    Cheers, harald

Maybe you are looking for

  • Programs stop responding when I try to print to PDF

    Info on what I'm using: OS: Windows 7 Home Premium, SP1, 64-bit Using Adobe Acrobat 8 Professional, version 8.1.0, up to date on updates In this example, Microsoft Office 2007, no add-ons besides the Adobe Acrobat add-in that allows the creation of a

  • Elongated Startup Time with Update to Windows 8.1 Pro (64 bit)

    I've gone ahead and installed the Windows 8.1 Professional update after being quite happy with Win 8 Pro.  After about a month of waiting for an improvement in the Restart times - it takes approximately 3 minutes after signing in for me to have a use

  • "no bootable device" on rMBP Win 7 x64 install

    I'm trying to install Win7 Premium Home x64 on my rMBP. I follow the the Bootcamp wizard, which makes a USB drive from the Win7 ISO I made from my other computer (used ISO Buster on Windows 7, transferred to an ExFAT formatted USB drive). It reboots

  • Issue when submit my form

    Hi all, I have OAF page that contains a form to save Employee Data. This form has an MessageLovInputBean and MessageStyledTextBean, to enter or display manager full name. In processRequest i have done this code: OASwitcherBean managerSwthr= (OASwitch

  • WSI Validation in Jdeveloper

    I tried to validate a wsdl against the wsi standard like shown in: http://www.oracle.com/technology/products/jdev/howtos/1013/ws-i/wsi_howto.html But my jdeveloper (10.1.3.1) prompts: C:\Programme\OracleJdevSOA10.1.3Prod\jdev\mywork\wsia.bat -config