How to replace escape characters in a string ?

Hi All,
In my application I came across a problem where I want to replace a substring (contains escape characters also) with another string. The below shown code will replicate my problem :
public class StringSearchAndReplace {
  public static void main(String args[])   {
    String stmt = " \\pntext\\bullet\\tab The question as to ";
    String newStmt = stmt.replaceAll("\\bullet\\tab",  "B");
    System.out.println("BEFORE: " + stmt + "\n");
    System.out.println("AFTER: " + newStmt);
}Here I want to replace "\\bullet\\tab" with "B". I am unable to move further. Please help/suggest me in this regard.
Its urgent.
Thanks in advance.

Satyaprasad_Mylavarapu wrote:
Hi All,
In my application I came across a problem where I want to replace a substring (contains escape characters also) with another string. The below shown code will replicate my problem :
public class StringSearchAndReplace {
public static void main(String args[])   {
String stmt = " \\pntext\\bullet\\tab The question as to ";
String newStmt = stmt.replaceAll("\\bullet\\tab",  "B");
System.out.println("BEFORE: " + stmt + "\n");
System.out.println("AFTER: " + newStmt);
}Here I want to replace "\\bullet\\tab" with "B". I am unable to move further. Please help/suggest me in this regard.
Its urgent.
Thanks in advance.If the String you're trying to replace contains a slash you need four slashes (double it for java, then again because String.replaceAll takes a regular expression)
So I think what you're looking for is:
String newStmt = stmt.replaceAll("\\\\bullet\\\\tab",  "B");I haven't tested that though.

Similar Messages

  • Regular expressions-how to replace [ and ] characters from a string

    Hi,
    my input String is "sdf938 [98033]". Now from this given string, i would like to replace the characters occurring within square brackets to empty string, including the square brackets too.
    my output String needs to be "sdf938" in this case.. How should I do it using regular expressions? I tried several possible combinations but didn't get the expected results.

    "\\s*\\[[^\\]]+\\]"

  • 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...

  • How to replace special characters in string.

    Hello,
    I want to replace special characters such as , or ; with any other character or " ".I find out there is no such function is java for this.There is only replace() but it accepts only chars.If anybody know how to do this?.
    Thanks,

    Hello,
    I want to replace special characters such as , or ;
    with any other character or " ".I find out there is no
    such function is java for this.There is only replace()
    but it accepts only chars.If anybody know how to do
    this?.
    Thanks,Can't you just do the following?
    public class Test
         public static void main(String[] args)
         String testString = "Hi, there?";
         System.out.println(testString.replace(',',' '));
    }

  • Replace multiple characters in a string

    Hi, I have some string fields that contain special characters such as ô and û and I want to replace them with ō and ū, and their upper case equivalents as well. How do I write a single formula that would find any of these characters in a string and replace them?
    Thanks,
    Will

    replace(replace(replace(replace(x,'ô','ō'),'û','ū'),'Ô','Ö'),'Û','Ü');
    where x is the string field.  I suggest using the unicodes rather than the actual character.  I do not think that I have the correct uppercase characters.  Please ensure that they are correct in your formula.

  • Need help in replacing special characters in a string

    Hi,
    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    with regards.
    sumanth.

    please let me know the best way to replace all the special characters in a string with space.
    other than alphabets and numbers
    >
    Sumanth Nag Kristam wrote:
    > actually i need to replace hexa decimal char 0X1A in a string.... that is 'substitue' as per the chart
    > any pointers....
    >
    > chk the link for the ASCII codes
    > http://www.techonthenet.com/ascii/chart.php
    But in Hexa decimal value there is no special characters?

  • How to replace a character in a string

    Hello Powerusers
    First i'me new in the applescripting so hope you can tell me a few hint to get on.
    I Have been trying to find a way to replace characters in a string using applescript. but with no luck
    Anybody having a script that can give me a clue on this.
    I'me normally programming in windows.... yeah i know there is a first time for everything.

    Okay i solved my problem but why arent the folder renamed?
    property oldfolder : ""
    property newfolder : ""
    property SS : "."
    property RS : " "
    to replaceText(someText, oldItem, newItem)
         replace all occurances of oldItem with newItem
              parameters -     someText [text]: the text containing the item(s) to change
                        oldItem [text, list of text]: the item to be replaced
                        newItem [text]: the item to replace with
              returns [text]:     the text with the item(s) replaced
              set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}
              try
                        set {itemList, AppleScript's text item delimiters} to {text items of someText, newItem}
                        set {someText, AppleScript's text item delimiters} to {itemList as text, tempTID}
              on error errorMessage number errorNumber -- oops
                        set AppleScript's text item delimiters to tempTID
                        error errorMessage number errorNumber -- pass it on
              end try
              return someText
    end replaceText
    tell application "Finder"
              set these_items to the selection
    end tell
    repeat with i from 1 to the count of these_items
              set this_item to (item i of these_items) as alias
              set this_info to info for this_item
              set oldfolder to name of this_info
              set newfolder to replaceText(oldfolder, SS, RS)
              set name of this_info to newfolder
    end repeat

  • How to search special characters in a string

    Hi all,
    I want to search special characters in all string columns and all rows in the table.
    The table has about 5 string columns and about 5.000.000 rows. For each row and column, I have to search entries, which included special characters like ", !, ? or something else (f.ex. "Mama?Mia" or "!!!Hotel out of order!!!"). The problem, the character could stand at each position in the string.
    What's the best and most performance possibility to search such entries?? Is it possibility only by SQL; is there a special function for this?? Or must I use PL/SQL.
    Thanks for helping
    Dana

    HTH
    Laurent Schneider
    OCM DBA
    SQL> select * from z;
    S
    Mama?Mia
    a b c
    123
    SQL> select * from z where translate(s,'~ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890','~') is not null;
    S
    Mama?Mia
    SQL> select * from z where regexp_like(s, '[^[:alnum:][:space:]]');
    S
    Mama?Mia

  • How to use escape characters in expdp

    Hi All,
    Am exporting the dump by using expdp as follows
    expdp XXXXX/YYYYYY schemas=XXXXX INCLUDE=TABLE:\"LIKE('EXT_%')\" directory=DUMPDIR1 dumpfile=XXXXX_18-Dec-2012.dmp logfile=exp_XXXXX_18-2012.log
    rocessing object type SCHEMA_EXPORT/TABLE/TABLE
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
    Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
    Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
    Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    . . exported "XXXXX"."EXT_COLLATERAL"                     556.5 KB    2543 rows
    . . exported "XXXXX"."EXT_CUSTOMER"                       184.1 KB    1210 rows
    . . exported "XXXXX"."EXT_ACCOUNT"                        142.8 KB    1116 rows
    . . exported "XXXXX"."EXT_CUSTOMER_IDENTIFICATION"        126.6 KB    1210 rows
    . . exported "XXXXX"."EXT_LN_ACCOUNT"                     111.3 KB     965 rows
    . . exported "XXXXX"."EXT_LN_ACCT_DISBRSMNT_EVENT"        102.5 KB     965 rows
    . . exported "XXXXX"."EXT_PERSON"                         108.7 KB    1210 rows
    . . exported "XXXXX"."EXT_DP_ACCOUNT_SUMMARY"             77.92 KB     151 rows
    . . exported "XXXXX"."EXT_LN_ACCOUNT_DISBURSEMENT"        100.4 KB     965 rows
    . . exported "XXXXX"."EXTENSION_BASIS_TYPE_REF"           5.296 KB       3 rows
    . . exported "XXXXX"."EXTERNAL_BANK"                      11.23 KB      40 rows
    . . exported "XXXXX"."EXTERNAL_BANK$AUD"                  12.73 KB      42 rows
    . . exported "XXXXX"."EXTRACTION_SVCE_REF"                5.289 KB       2 rows
    . . exported "XXXXX"."EXT_DP_ACCOUNT"                     24.64 KB     151 rows
    . . exported "XXXXX"."EXT_DP_ACCOUNT_INTEREST"            37.72 KB     151 rows
    . . exported "XXXXX"."EXTERNAL_SMS"                           0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_BLOCK"                      0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHARGE"                     0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHARGE_SUMMARY"             0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHARGE_TIER"                0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHEQUE_BOOK_ORDER"          0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHEQUE_INVENTORY"           0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_RELATIONSHIP"               0 KB       0 rowsit export fine.. But my requirement is needs to export tables start with EXT_%
    here expdp exports all table starting with EXT% how to specifies escape character in export option.
    excepted result
    . . exported "XXXXX"."EXT_COLLATERAL"                     556.5 KB    2543 rows
    . . exported "XXXXX"."EXT_CUSTOMER"                       184.1 KB    1210 rows
    . . exported "XXXXX"."EXT_ACCOUNT"                        142.8 KB    1116 rows
    . . exported "XXXXX"."EXT_CUSTOMER_IDENTIFICATION"        126.6 KB    1210 rows
    . . exported "XXXXX"."EXT_LN_ACCOUNT"                     111.3 KB     965 rows
    . . exported "XXXXX"."EXT_LN_ACCT_DISBRSMNT_EVENT"        102.5 KB     965 rows
    . . exported "XXXXX"."EXT_PERSON"                         108.7 KB    1210 rows
    . . exported "XXXXX"."EXT_DP_ACCOUNT_SUMMARY"             77.92 KB     151 rows
    . . exported "XXXXX"."EXT_LN_ACCOUNT_DISBURSEMENT"        100.4 KB     965 rows
    . . exported "XXXXX"."EXT_DP_ACCOUNT"                     24.64 KB     151 rows
    . . exported "XXXXX"."EXT_DP_ACCOUNT_INTEREST"            37.72 KB     151 rows
    . . exported "XXXXX"."EXT_ACCOUNT_BLOCK"                      0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHARGE"                     0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHARGE_SUMMARY"             0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHARGE_TIER"                0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHEQUE_BOOK_ORDER"          0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_CHEQUE_INVENTORY"           0 KB       0 rows
    . . exported "XXXXX"."EXT_ACCOUNT_RELATIONSHIP"               0 KB       0 rowsThanks
    Sami.

    expdp XXXXX/YYYYYY schemas=XXXXX INCLUDE=TABLE:\"LIKE('EXT\\_%')\" directory=DUMPDIR1 dumpfile=XXXXX_18-Dec-2012.dmp logfile=exp_XXXXX_18-2012.log
    or
    expdp XXXXX/YYYYYY schemas=XXXXX INCLUDE=TABLE:\"LIKE('EXT\_%')\" directory=DUMPDIR1 dumpfile=XXXXX_18-Dec-2012.dmp logfile=exp_XXXXX_18-2012.log its not working which gives the following error
    Estimate in progress using BLOCKS method...
    Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 0 KB
    ORA-39165: Schema XXXXX was not found.
    ORA-39168: Object path TABLE was not found.
    ORA-31655: no data or metadata objects selected for job
    Job "XXXXX"."SYS_EXPORT_SCHEMA_01" completed with 3 error(s) at 10:30:13when i gives EXCLUDE option then it working but it also exporting all tables
    expdp XXXXX/YYYYYY  schemas=XXXXX EXCLUDE=TABLE:\"LIKE('EXT\\_%')\" directory=DUMPDIR1 dumpfile=XXXXX_19-Dec-2012.dmp logfile=exp_XXXXX_19-Dec-2012.log
    Estimate in progress using BLOCKS method...
    Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 133.1 MB
    Processing object type SCHEMA_EXPORT/USER
    Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
    Processing object type SCHEMA_EXPORT/ROLE_GRANT
    Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
    Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
    Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
    Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
    Processing object type SCHEMA_EXPORT/TABLE/TABLE
    Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
    Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type SCHEMA_EXPORT/TABLE/COMMENT
    Processing object type SCHEMA_EXPORT/PACKAGE/PACKAGE_SPECany idea or suggestion?
    Thanks
    Sami

  • Replace Special Characters in a String

    Let's say someone copies the folowing list and pastes it into a Javascript prompt box:
    302304
    305678
    245675
    How do I manipulate the string so it reads:
    302304 305678 245675
    In other words, how do I replace the manual line breaks in a string with spaces?
    Thanks!

    \r and \n are both \s characters.
    This is functionally equivalent to what you have...
    stringName = stringName.replace(/\s/g,' ');
    I highly recommend browsing this website (lots of useful info there):
    http://www.regular-expressions.info/
    Harbs

  • How to remove escape characters

    When there is string in my source like my boss is "chandra" it is taking like it is taking like "my boss is ""chandra""".
    Could you please give me suggestion how I can eliminate unnecessary escape character.
    -Pallav

    Hi Pallav,
    Is possible to you just use a replace function at a stage area mapping?
    like: (assume that "my boss is ""chandra""" is at col1)
    replace(col1, '""', '"')
    it's means, replace 2 " by 1 "

  • 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 &amp;#246; or &amp;#214;
    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 not to escape characters in 3.1

    Hello
    In Apex 2.0 i used to store html text in an item; if i used it in an html region or in a label it worked fine, i mean it showed the formatted text.
    In Apex 3.0, it shows the full html text as if i used escape special characters but i want it html formatted; is that a migration error? even if a create a new app happens the same thing. How can we solve it?
    Thanks

    The item type needs to be (a) an application item, or (b) Display as Text (escape special characters, does not save state) with its condition set to Never.
    Scott

  • PHP: automatically replace alphanumeric characters in a string

    Quick question:
    How do I program a PHP script to replace all non-alphanumeric
    charters within a string, with underscores?

    .oO(AngryCloud)
    >Yes, this does help, although it is only alphabetic.
    >
    >Will changing the line to this make it alphanumeric?:
    >
    >$new_string = preg_replace("/[^a-zA-Z0-9]/", "_",
    $string);
    Did you try it? ;-)
    You could also use this shorter pattern:
    /[^a-z\d]/i
    Should be the same (\d matches decimals and the /i modifier
    makes the
    entire thing case-insensitive).
    Micha

  • How to replace special characters with html code characters automatically?

    A colleague and I work on these html pages. They eventually end up as emails, but we have the cold fusion server to pre process them. One thing we are trying to do is eliminate problems caused by unencoded copyright, trademark and smart quote symbols.
    How could I create an array of find / replace commands in the header so it processes the HTML with correct character codes.
    I"m not cold fusion aware, so any kind of starter info would be great. Eventually I might add more replacements to the array.
    As an example TM (font character) would process to &trade; and a smart quote or apostrophe would process to a straight one. an en dash character would become &ndash;
    Because we copy paste from places, this often happens and it seems like cold fusion could solve the problem quickly and repeatedly all at once.
    thanks for any help
    -smick

    CF has a built in HTMLEditFormat function for handling <  &  > characters.  For handling trademark and smart quote characters you might try searching for a user defined function at http://cflib.org or writing a user defined function yourself that will handle the specific characters needed in your application.

Maybe you are looking for