Replacing unicode character literals with characters.

Hi, say i have a String like:
String example = "\\u1234 llamas \\uabcd\\c0d4";etc.
How would I replace all the unicode literals (\\u1234 etc.) with the actual characters?
Is there an easy way to do this?

sabre150 wrote:
It is interesting that every time I post my solution to this problem it is ignored. OK, it does require a third party component and it does use a regex but it does work. All one has to do is to construct a UnicodeRewriter and then useIt does involve adding a about 50 lines of code or more for what ought to be quite a trivial operation. And if you don't need a Rewriter for anything else that's an overhead, even if you just copy and past it.
This rather relates to a discussion I initiated last month, how good a reason do you need to import 3rd party libraries. Tastes vary
How about:
byte[] bytes = ("X=" + originalString + "\n").getBytes("ISO-8859-1");
InputStream bis = new ByteArrayInputStream(bytes);
Properties p = new Properties();
p.load(bis);
String result = bis.getProperty("X");That's less code than your subclass alone, let alone the rewriter. OK it's a bit weird and not totally bulletproof should, say, newlines find their way into your input stream.
Also it uses an "official" interpreter of escaped Java strings rather than making one up.
Edited by: malcolmmc on Jul 11, 2009 8:53 AM

Similar Messages

  • How replace any character typed with other characters useing Keymap in JTC!

    Hi,
    I want to map some key to some character(unicode) using Keymap interface.
    What`s the easiest and shortest way to do it?
    Thank you in Advance,
    chandracar

    I test it on an english Window and worked well but on
    an arabic/farsi window didn`t work well.The character
    that appears in text component isn`t the character
    that i defined in the program.We would need to see the source code for your CustomKeyTypedAction (or whatever you called it) to help you any further.
    How can i define a keymap that independent from the
    OS language that works same in all OS languages
    like english or non-english?I'm no expert, but that sounds like a big project. At the least, you would need a conversion table for every pair of languages, but that would only work when the user's keyboard had enough keys to produce all the characters in the target language. Some languages have so many characters that even purpose-made keyboards can't hold them all, and special InputMethods have to be used to enter them (and I don't know anything about those).

  • Issue related to Unicode character compatibility

    Request for the help on the issue related to Unicode character compatibility with Oracle 11G R2 32 Bit DB.
    Issue description: I have created a Profile in my application and named it with Unicode characters(German\Russian\Latvian…. alphabets), while opening the profile its throwing an error message “Invoice profile cannot be found in database.”
    During the Oracle database installation I have selected the Database character set as Unicode UTF-8. As per our application guide it considers only the Database characterset and not the National character set.
    Let me know if I have to still do some additional settings with respect to this globalization settings.
    Thanks,
    Brij

    I don't know what the application does, so I don't also know the profile role and what - exactly - can't be found in the database. At least 'a invoice profile' is not a native Oracle object.
    So it's not possible to analyze the application problem.
    On the database side characterset UTF8 (although I would prefer the 'newer' AL32UTF8 characterset) is appropriate in a globalized environment. What to do in the interaction between application and database - that depends highly on the application itself.
    Werner

  • Engraving with a unicode character

    didn't know where the best place to ask this question was...
    i'm about to replace my 5th gen ipod with an 80GB ipod classic. i want to get it engraved with a unicode character (ॐ), but when i type it into the "Line 1" field it doesn't show up. It shows up as a question mark (?). Is this just on the website, or will it actually engrave as a question mark. I really want to make sure it engraves with what i want since i can't return engraved items.
    Please and thank you

    Hi Mexigerm,
    Accented and other special characters, including "~*\, cannot be used in your iPod engraving or gift message.
    Unfortunately your character is also included on the list.
    If you proceed with the engraving, a question mark will appear... Sorry!
    Hope this helps!
    !http://signatures.mylivesignature.com/54486/122/A57996D55BE7ABB4A67DE686D381A27 4.png!

  • Find/Replace Extended Character Set characters in filenames in one pipeline

    Hello all,
    I have to work with some very bored people. Instead of putting a dash (hex 2d) into a filename, they opt for something from this
    set of extended characters, which makes my regular expressions fail.  IS there a way I can efficiently find & replace anything outside the standard character set
    in one pipelinewithout finding and replacing a character at a time?
    So,I'd like something like:
    get-childitem * | where-object $_.name -match '\x99' | rename-item -newname { $_.name -replace '\x99','='}
    from hex 80 to hex FF rather than a for-each.
    Thanks.

    Answer would depend on the way you want to replace... Easier if you want replace any char in set with selected char:
    $Name = -join (180..190|%{[char]$_})
    New-Item -ItemType File -Name $Name
    Get-ChildItem * | Rename-Item -NewName {
    [regex]::Replace(
    $_.Name,
    '[\xB4-\xBE]',
    } -WhatIf
    But if you want it more complicated, you may do that too. E.g. defining hashtable that can be used to replace individual elements:
    $Replacer = @{}
    foreach ($Char in (180..190 | % { [char]$_ })) {
    $Replacer.Add(
    [string]$Char,
    (echo _, -, =, . | Get-Random)
    $Replacer
    Get-ChildItem * | Rename-Item -NewName {
    [regex]::Replace(
    $_.Name,
    '[\xB4-\xBE]',
    $Replacer[$args[0].Value]
    } -WhatIf
    Using this syntax make it possible to include some logic in replace. E.g. you could easily use switch to decide what to do with given string:
    Get-ChildItem * | Rename-Item -NewName {
    [regex]::Replace(
    $_.Name,
    '[\xB4-\xBE]',
    switch ($args[0].Value) {
    º { "0" }
    µ { "u" }
    ¹ { "1" }
    ¸ { "," }
    Default { "_" }
    } -WhatIf

  • Replacing Unicode characters in a String

    I have a text as a String and in this text which is foreign language appears sometimes characters in Unicode format as ö or Ö
    The question is, how can I convert this String so these Unicode characters would become readable characters.
    Thank you for any lead...

    :-) Interesting - twice in 10 minutes I'm recommending the use of Elliott Hughes' class. See http://elliotth.blogspot.com/2004/07/java-implementation-of-rubys-gsub.html .
    You just have to write a regular expression to match the terms ( "&#(\\\d+)"), extract the number as a string (group(1)) then use the Integer.parseInt(the numeric string) and cast to a char.
    Edited by: sabre150 on Feb 9, 2012 9:53 AM
    This is an example I wrote a couple of years ago (and published on the old Sun site forums) that does pretty much exactly what you need
    import e.util.Rewriter;
    public class Sabre20090919
        public static void main(String[] args) throws Exception
            String title = "& #26412;& #26399;& #28136;& #21033;\n" +
                    "& #22522;& #26412;& #27599;& #32929;& #30408;& #39192;\n" +
                    "& #32380;& #32396;& #29151;& #26989;& #21934;& #20301;& #28136;& #21033;\n" +
                    "& #26371;& #35336;& #21407;& #21063;& #35722;& #21205;& #32047;& #31309;& #24433;& #38911;& #25976;\n" +
                    "& #26222;& #36890;& #32929;& #27599;& #32929;& #30408;& #39192;\n" +
                    "& #31232;& #37323;& #27599;& #32929;& #30408;& #39192;\n";
            Rewriter rewriter = new Rewriter("&\\s*#(\\d+);")
                @Override
                public String replacement()
                    return Character.toString((char) Integer.parseInt(group(1)));
            title = rewriter.rewrite(title);
            System.out.println(title);
            System.out.print("Unicode :\"");
            for (char ch : title.toCharArray())
                System.out.printf("\\u%04x", (int) ch);
            System.out.println("\"");
            byte[] asBytes = title.getBytes("big5");
            for (byte b : asBytes)
                System.out.printf("%02x ", (int) (b & 0xff));
            System.out.println();
    }The rest is just a test harness.
    Edited by: sabre150 on Feb 9, 2012 10:02 AM
    Removed redundant code

  • How to replace the '&' character with '&' in xi

    Hi,
    i need to replace the '&' character with ' &'.but i f i am converting it is displaying as '&' because internally '&' = '&'.
    beacuse of this it is not converting.
    is there any possiblity to change the  standard conversion in xi.

    Graphical mapping does not support special character like & , <,> to be mapped.
    You can encode & as and in UTF-8 only.
    if you want the special character to be used, Opt XSLT mapping with ISO-8859-1 encoding
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" encoding="ISO-8859-1"/>
    <xsl:template match="/">
    <xsl:copy-of select="*" />
    </xsl:template>
    </xsl:stylesheet>
    How to Work with Character Encodings in Process Integration (NW7.0)
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42

  • How to replace a character in a string with blank space.

    Hi,
    How to replace a character in a string with blank space.
    Note:
    I have to change string  CL_DS_1===========CM01 to CL_DS_1               CM01.
    i.e) I have to replace '=' with ' '.
    I have already tried with <b>REPLACE ALL OCCURRENCES OF '=' IN temp_fill_string WITH ' '</b>
    Its not working.

    Hi,
    Try with this..
    call method textedit- >replace_all
      exporting
        case_sensitive_mode = case_sensitive_mode
        replace_string = replace_string
        search_string = search_string
        whole_word_mode = whole_word_mode
      changing
        counter = counter
      exceptions
        error_cntl_call_method = 1
        invalid_parameter = 2.
    <b>Parameters</b>      <b> Description</b>    <b> Possible values</b>
    case_sensitive_mode    Upper-/lowercase       false Do not observe (default value)
                                                                       true  Observe
    replace_string                Text to replace the 
                                         occurrences of
                                         SEARCH_STRING
    search_string                 Text to be replaced
    whole_word_mode          Only replace whole words   false Find whole words and                                                                               
    parts of words (default                                                                               
    value)
                                                                               true  Only find whole words
    counter                         Return value specifying how
                                        many times the search string
                                        was replaced
    Regards,
      Jayaram...

  • Connecting to EMS fails with No mapping for the Unicode character exists in the target multi-byte code page

    I am getting the following error when trying to connect to both my exchange servers.
    New-PSSession : [ex2013-002.nafa.ca] Connecting to remote server ex2013-002.nafa.ca failed with the following error
    message : No mapping for the Unicode character exists in the target multi-byte code page. For more information, see
    the about_Remote_Troubleshooting Help topic.
    At line:1 char:12
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ht ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
       gTransportException
        + FullyQualifiedErrorId : 1113,PSSessionOpenFailed
    EMS used to connect ok. I am not sure if there is any connection but Outlook was installed recently on the exchange server to enable mailbox level backups.
    Any help would be appreciated.
    Steve Hurst

    Hello Steve,
    Firstly, you cannot install Outlook with Exchange because they share certain dll files.
    About the EMS question, I suggest we try rebuilding the powershell virtual directory. If it still does not work, check the application log for more referernce.
    Thanks,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Simon Wu
    TechNet Community Support

  • Safari for Windows is NOT compatible with Unicode 3.1 CJK characters!

    This is an "old" problem since Safari for Windows was initially released. In the meantime, the problem is still not fixed in the latest version 4.0.3 (531.9.1).
    Not only Safari (for Windows) does not properly show homepages that contain Unicode 3.1 CJK characters, but it also fails to show Unicode 3.1 CJK characters (it shows "squares" instead) in the whole application, such as Search box and all dialog boxes. Will this be fixed in the next release?
    By the way, it is strange that Safari 4 for Mac is Unicode 3.1 compatible.

    To speak more precisely, the Safari for Windows doesn't support CJK characters of Unicode CJK Unified Ideographs Extension B.
    The following test illustrates the incompatibility of Safari for Windows:
    1. Sample text displayed in Firefox 3.0.2 on Fedora 9.
    http://farm4.static.flickr.com/3020/3002743180_e026d5c84b.jpg
    2. Sample text displayed in Safari 3.x/4.x on Windows XP with "MingLiu Ext-B" (an Ext-B font provided by Microsoft) installed.
    http://farm4.static.flickr.com/3224/2971019999_1c113109a9.jpg

  • How to replace the Losing fonts with scrip in photoshop,by script

    Frequently,I Receive some PSD files, It is did by Other people.
    When I open it with my computer,I find it missed a lot of fonts.
    Some times,I have this fonts, but the name is not  like with the fonts of the PSD file.
    So,I need to replae the Losing fonts, but it  always have a lot, It wast my much times.
    In Indesign, it is Very easy~~
    Could you help me Achieve it by scrip in Photoshop?
    Thank you very much

    Hi Sridhar,
    I would like to Replace the Charecter values with numeric value in my string.
    Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
    So, if i understand you correctly, you want to replace all characters in a string with 9 as in the above example, irrespective of position of the character, if so try with the below code.
    DATA: l_str TYPE string.
    l_str = 'ASKHSIUDNSBDKJSDH124312431243124saasdfsf'.
    REPLACE ALL OCCURRENCES OF REGEX '\D' IN l_str WITH '9'.
    IF sy-subrc EQ 0.
      WRITE: l_str. "Result will be 9999999999999999912431243124312499999999
    ENDIF.
    Regards,
    Chen
    Edited by: Chen K V on Jun 13, 2011 12:36 PM

  • Replace a character in a String array

    I have an array of strings and am trying to replace the ' character with a space. I keep getting either a cannot be applied or cannot resolve symbol error. Can anyone help?
    String arrayList = request.getParameter("field");
    String newList = arrayList.replace("\'", " ");

    the replace method of the String class takes two parameters and both of them are characters not strings use it like this
    arrayList.replace('\'', ' ');that should fix it

  • Replacing a character in a String

    Hi All,
    How can I replace a character ' which appears in a String into \'

    There is a method in String that replaces all
    occurrences of one character with anothercharacter.
    It's called, hold your breath now, "replace".But tho OP wants to replace one character with two
    characters :)You're right, I missed that. Well, serves me right for being sarcastic. :-)

  • Display Unicode Character in Swing Objects

    I am trying to display Chinese Characters using Swing GUI.
    I created Unicode strings using escape character \uXXXX
    I displayed \u4e00 successfully
    However when I tried to display \ub8db i got a square box displayed instead.
    I am using: Winnt ver 4 ,RichWin 97
    private Object listData[] = {
    new String("\ucfe3\ub8db"), // Two boxes displayed in list
    new String("\u4e01\u4e00"), // Characters displayed correctly
    new String("Third selection")
    To hope to get some replies ASAP. Thanks!!!
    Regards,
    Patrick

    Hi Patrick,
    Yeh, fonts are rather ubiquitous when it comes to internationalization. The fact that the font.properties files still exist confuses a lot of people. In reality, Sun doesn't support them any more, and they aren't all that useful if you're actually deploying your code onto other machines.
    So, to answer your questions... :D
    1) Each component will have a font set on it. To start with, each component will end up with the JDK default, usually the Dialog font in Java. From memory, I think this maps to Arial on Windows systems, though I'm not sure if RichWin alters this in anyway, as I haven't used it myself.
    You can check the available fonts on your machine by calling:
    GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    This returns an array of strings. You can basically create a new font from any of the names that appear in here. For instance, if one of the strings was "Arial Bold", you could create the following font:
    Font myFont = new Font("Arial Bold", Font.PLAIN, 12);
    2) The best way is to simply create the font you want on startup. If you can't rely on the font
    you need being installed on every machine you plan to run your program on, the best solution is to either install it on startup, or carry it around with you.
    Have a look at Font.createFont(), as it allows you to create a new Font object from a *.TTF file (a TrueType font). In JDK1.3, this is buggy, leaving a large temp file behind every time you run it, but I've already tried this under Merlin Beta, and it's fixed and working fine.
    The reason this is handy is because the font we keep talking about on here, Arial Unicode MS, is a TrueType font. So you can carry the font around with you, and load it on startup using this call.
    Arial Unicode MS is a 23Mb font, but it's capable of displaying just about any character you could imagine.
    The trick from there, once you've loaded your font, is to make sure you call setFont() on just about any component you create. Menus are a cow - you've got to listen for events, as the dropdown menus don't always get the font straight away. But other than that, it's fairly simple.
    3) The short answer is to call the getAvailableFontFamilyNames() call above, and look for any familiar font names. If you can't find any, you know you're not going to be able to display anything.
    Windows seems to have standard fonts for the international languages. In Chinese, this is SimHei for Simplified (mainland) Chinese, and MingLiU for Traditional (Taiwanese) Chinese. Simplified covers about 30,000 Kanji, while Traditional covers around 80,000.
    So for Chinese, you would look for "SimHei" and "MingLiU", plus any of the fonts capable of displaying anything, like "Arial Unicode MS". If none of these strings are in the array, you may want to carry the Arial Unicode MS installer around with you and execute it. This file is about 11Mb, and is available as a download off the Microsoft website.
    4) Probably about the most useful thing I've come across is the Sun I18N tutorial on this very website. There isn't a heck of a lot out there, unfortunately. About the only other things I can recommend are http://www.unicode.org for the Unicode character codes, and http://www.njstar.com for NJStar Communicator, which you'll find useful if you're working with Chinese.
    Oh, and watch this forum, of course. ;D
    Hope that helps!
    Martin Hughes

  • ** Plz help me in displaying unicode character **

    Hi,
    I hava a problem with the following code. Actually I want to display some arabic character with the help of unicode. Plz go through the following code.
    import java.awt.*;
    class Unicode extends Frame
    public static void main(String args[])
    Frame f = new Frame("Unicode");
    f.setSize(200,200);
    String str="\u0600";
    TextField tf=new TextField(str);
    f.add(tf);
    f.setVisible(true);
    I m trying to print that character on a textfield. However, this is not the requirement but for only testig purpose. I get the character '?' in the resulting textfield. plz tell me that how can I use unicode to print other languages character anywhere like on awt, swing or in html. plz reply soon . Thanks
    Fahad Ahmed

    \u0600 is an unassigned Unicode character, so there's no way to do that. However I assume you mean you want to display Arabic characters such as \u0627, Arabic Letter Alef (&#x0627). Then you need to find a font that can render those characters properly, and assign that font to the TextField using its setFont() method.
    I notice you are using AWT, which probably means you are trying to do this in an applet. If that's the case then "find a font and use it" is going to be a big problem, because you don't know what fonts your clients' computers have available.

Maybe you are looking for

  • Flash CC does not support .swf then how do i edit .swf?

    Hello, I am at a stuck point with my clients website i downloaded a template for him and have everything good to go except for i have no experience in flash files and the main piece to this websites decor is a flash .swf file. As i stated i have no e

  • Error Message in DW, PLEASE HELP? :)

    Hello, all.. I have a screen capture of the error message I'm getting when I try to save an htm file I've created for a page. Had the site all built and when went in to make a quick change to site, the error started popping up and now I can't save an

  • Jpeg quality when exporting

    Is there a way to adjust the jpeg quality when exporting or editing? I can change the image size, which is helpful, but it would be nice if I could change the jpeg compression in order to reduce the file size. Thanks!

  • I can't find the download window anymore since I upgraded to Mountain Lion

    I used to be able to see the progress of all my download in its own widow and now that does't pop up anymore since the upgrade. I really liked that feature and want it back. Is there anyway to get that back?

  • Roles Issue?

    Hi All, The roles are migrated to BP1then the old queries under roles are deleted from shred queries now how to find the queries under which role. Thanks in Advance, Ravi