ReplaceAll / regexp / escaping a string

Hi, I have a question about escaping a string for use with replaceAll. My objective is to replace all instances of string1 with string2 so I have been doing so using replaceAll. This works well however with it relying on regexp's I have some questions about escaping.
I want to, for example, replace [%PARAM%] with '100%' however this starts to get in to the murky (to me) worlf of regular expressions. After some testing I realize I have lots of characters that are important to the regexp and I can avoid problems by escaping them like this:
\\[\\%PARAM\\%\\] with '100\\%'
This works however the values will be parsed out of strings the user enters so clearly I don't want them to have to add the escape characters, is there a way I can:
a) Tell it to ignore special characters so it is treated like a basic searcha nd replace or
b) Autmatically escape any problematic characters in the string before calling replaceAll?
If there is another approach you would recommend I'd be very interested to hear it too.
Thanks in advance,
Chris.

Don't get me started on the evils of writing Java inside JSP!
Anyway, if you look at the documentation I helpfully linked for you, you'll see that the replace method that can take two Strings (two CharSequences to be precise) versus just two chars was introduced in version 1.5, so you must be using an older compiler.
You should consider upgrading to 1.6. Even 1.5, let alone the version you must be using, is in its Java Technology End of Life (EOL) transition period.
[http://java.sun.com/javase/downloads/index_jdk5.jsp]

Similar Messages

  • Escape XML Strings with JDK class

    Hi,
    can anyone tell me how to escape XML-Strings with classes of the JDK?
    When searching I only was pointed to StringEscapeUtils from apache.commons.lang, but we would prefer to use the JDK instead of integrating an external lib.
    Our aim is to escape an XML attribute, so a CDATA is not applicable for us in this case.
    Thanks
    Jan

    I implemented it by myself:
    public static String escapeXmlAttribute(String attributeValue) {
            StringBuffer result = new StringBuffer();
            for (int c = 0; c < attributeValue.length(); ++c) {
                if (attributeValue.charAt(c) == '"') {
                    result.append("&#34;");
                } else if (attributeValue.charAt(c) == '&') {
                    result.append("&#38;");
                } else if (attributeValue.charAt(c) == '<') {
                    result.append("<");
                } else if (attributeValue.charAt(c) == '>') {
                    result.append(">");
                } else {
                    result.append(attributeValue.charAt(c));
            return result.toString();
        }{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • .. in String.replaceAll / regexp

    Hello,
    I have now tried and read ages but cannot get the solution (having a bit experience in Perl regexpt also...). I simply want to replace two sequencing full stops within a string to null, like this:
    str = str.replaceAll("..", "");
    However, I cannot manage to, . having a special meaning in regexps. I tried things like \Q..\E or \.\. and so on, but it never works or even compiles. I think I have not understood some fundamental stuff... :-)
    Thanks for any help!
    Greetings, Timo

    Hello Legosa,
    That did it! However, I really do not understand, cos backslash being an escape char, I would have expected this output:
    \\.\\. => \.\.
    The first backslash being the escaper for the second. Well...
    But it works, big thanks again,
    Greetings, Timo

  • ReplaceAll regexp and JavaScript

    I want to write a function that will escape special characters in a String so that they render correctly in JavaScript.
    For example, if a string contains a tab, I want the tab to be replaced by \t and so on for all the escape characters : \', \", \\, \b, \f, \n, \t and \r.
    Here is my function so far :
    public static String JSStringFormat(String value) {
        String result = "";
        if (value != null) {
            result = value;
            result = result.replaceAll("\'", "\\\\'");
            result = result.replaceAll("\b", "\\\\b");
            result = result.replaceAll("\f", "\\\\f");
            result = result.replaceAll("\n", "\\\\n");
            result = result.replaceAll("\t", "\\\\t");
            result = result.replaceAll("\r", "\\\\r");
        return result;
    }So far, this works... But I can't find the solution for \\ and \"... I've tried many things but nothing works...
    Anyone can help ?

    replaceAll("\"", "\\\""); // I thinkIt throws compilation error on this line itself. If
    you are using an IDE, it wont allow you to go further
    with that line.
    replaceAll("\\\\", "\\\\\\\\"); // I think.
    I had a slight error in the quote one the replacement string needed two more quotes. This works:         String str = "\\a \"xyz\" \\ b";
            System.out.println(str);
            //System.out.println(str.replaceAll("\\" , "\\\\\\"));
            System.out.println(str.replaceAll("\"", "\\\\\""));
            System.out.println(str.replaceAll("\\\\", "\\\\\\\\"));Your line (commented above) gives Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
    ^
    regEx is particular about special characters like $
    and \.Yes, I know.
    So when you are using replaceAll, you have to
    be careful with regex, and replace them. For example,
    if you have a $ to be replaced, you have to replace
    it the following way.
    str.replaceAll("\\$", "\\\\\\$");Yes.
    >
    so, instead of directly using the $, you have to use
    "\\" that tells the regEx, yes this is a special
    character and treat it normally, like any other
    character.Yes.
    Along those same lines, like I said, you need \\ to get a single \ in a Java String. Then, if you want a literal \ in the regex, you need to provide the regex compiler with \\, which means your Java String literal must be \\\\.

  • Escaping entire String in a Regular Expression

    How does one escape an entire String in a Pattern? I thought that prefixing it with "\\Q" and postfixing with "\\E" would do the trick but this is functioning strangely. It also ignores the possibility of a "\\Q" and/or "\\E" within the String. I guess one could escape every meta-character but this seems like overkill. Is there a utility method somewhere? Why is it that:
    System.out.println("xx\\xx".replaceAll("\\Qx\\x\\E", "a"));yields xax but
    System.out.println("xx\\xx".replaceAll("\\Q\\\\E", "a"));outputs xx\xx?

    It looks like you've uncovered a bug. Specifically, when the Pattern parser sees the backslash that you're trying to match, it looks at the next character to see if it's an 'E'. It isn't, so the parser consumes both characters, then starts looking for the \E sequence again. The next character, of course, is the 'E', but the parser just sees it as a literal 'E' now. End result: instead of a Pattern for a single backslash, you get a Pattern for a backslash, followed by a backslash, followed by an 'E', as demonstrated here:    System.out.println("xx\\\\Exx".replaceAll("\\Q\\\\E", "a")); prints xxaxx.
    Since you're escaping the whole regex, you can work around the bug by leaving off the \E:    System.out.println("xx\\xx".replaceAll("\\Q\\", "a")); prints xxaxx.
    Or you can do what I do and use this method to escape strings instead of \B ... \E:  public static String quotemeta(String str)
        if (str.length() == 0)
          return "";
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < str.length(); i++)
          char c = str.charAt(i);
          if ("\\[](){}.*+?$^|".indexOf(c) != -1)
            buf.append('\\');
          buf.append(c);
        return buf.toString();
      }(This is why I've never run afoul of this bug, though I use regexes a lot.)
    I'll submit this to BugParade if you like. While I'm at it, I can submit an RFE to have them add a quotemeta method to Pattern.

  • Escaping a string for Javascript

    Hi!
    I've been using a lot of time on how to escape special characters in order for Javascript to accept a string. It seems like I need to escape single quotes, double quotes, backslash and newline.
    I've written some code, but I just can't get it to work.
    public static String editorSafeFilter(String text)
            if(text == null){
                return null;
            StringBuffer buffer = new StringBuffer(text.length());
             for (int i = 0; i < text.length(); i++) {
                char ch = text.charAt(i);
                 switch (ch) {
                   case 10: // '\n'
                        buffer.append(" ");
                        break;
                    case 13:
                         buffer.append(" ");     // '\r'
                         break;
                    case '\'':
                        buffer.append('\\');
                        buffer.append("\'");
                        break;
                    case '"':
                        buffer.append('\\');
                        buffer.append('\"');
                        break;
                    case '\\':
                        buffer.append('\\');
                        buffer.append('\\');
                        break;
                    default :
                        buffer.append(ch);
                        break;
            return buffer.toString();
        }Anyone have any links or sample code that works?
    thanks!
    Vidar

    It looks like you want the actual escape sequences... public static String editorSafeFilter(String text)
            if(text == null){
                return null;
            StringBuffer buffer = new StringBuffer(text.length());
             for (int i = 0; i < text.length(); i++) {
                char ch = text.charAt(i);
                 switch (ch) {
                   case '\012': // '\n'
                        buffer.append("\\n");     // '\n'
                        break;
                    case '\015':
                        buffer.append("\\r");     // '\r'
                        break;
                    case '\'':
                        buffer.append("\\\'");
                        break;
                    case '\"':
                        buffer.append("\\\"");
                        break;
                    case '\\':
                        buffer.append("\\\\");
                        break;
                    default :
                        buffer.append(ch);
                        break;
            return buffer.toString();
        }

  • Escaping xml string

    how to escape <,> in xml string to &lt; ,
    &gt;.is it possible to convert the entire xml string into this
    format
    ex:
    <root> <sample><id> 89
    </id></sample></root>
    this has to be converted into
    &lt; root&gt;. &lt; sample&gt;. &lt;
    id&gt;. 89 &lt; /id&gt;. &lt; /sample&gt;.
    &lt; /root&gt;.

    myString="<root> <sample><id> 89
    </id></sample></root>";
    myString.split("<").join("&lt;");

  • Escape, unescape strings

    JavaScript have escape(), unescape() functions.
    How i can in JDeveloper make unescape()?

    In Java?
    The Java equivalent to these Javascript functions is:
    import java.net.URLEncoder;
    import java.net.URLDecoder;
    String unescapedString = URLEncoder.encode(
      "The string ü@foo-bar
    String escapedString = URLDecoder.decode(
      "The+string+%C3%BC%40foo-bar"
    );If you're using Java 1.4, you should specify an encoding like this:
    import java.net.URLEncoder;
    import java.net.URLDecoder;
    String unescapedString = URLEncoder.encode(
      "The string ü@foo-bar", "UTF-8"
    String escapedString = URLDecoder.decode(
      "The+string+%C3%BC%40foo-bar", "UTF-8"
    );

  • Escape for string will add to db what should i do ??

    Hi,I want to escape for html and xml to store in db
    the blocks { and } doing problem and get me runtime error
    any idea to store it in mysql

    I'm not clear you are trying to say, but are you at least using a PreparedStatement?
    [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html]

  • Flex - Convert html escapes to string

    i want to convert this
    Error #1083: The prefix  &quot;http &quot; for element  &quot;//www.c.com::a &quot; is not bound.
    to this
    Error #1083: The prefix "http" for element "//www.c.com::a" is not bound.
    thanks

    Regular expressions.

  • JRC bug: apostrophe in string parameter passed to Crystal Report with Command datasource to SQL Server

    Post Author: nl11087
    CA Forum: JAVA
    A single quote/apostrophe in string parameter passed to a Crystal Report with Command datasource connecting to a SQL Server database, using sqljdbc driver does not escape the special character correctly. When doing a preview in the Crystal Reports IDE it allows you to escape the input parameter as expected and work correctly, but through the JRC component it fails. For string parameters without special sql server characters I experience no problems at all. When replacing the Command with a direct table there is also no problem.
    Reproduction:
    1. create a database db1, create a table table1 with a String type column col1.
    2. Create new report Report1.rpt, create a connection to above, Add Command using 'SELECT col1, col2, col3 FROM table1 WHERE col1 = '{?Par1}' . Add a parameter field Par1 : String
    3. In your java stand alone application using JRC add the parameter Par1 with a value "Jon Doe's Value" containing a single apostrophe. Export to PDF. (I also tried MSWord and this failed too, similar behavior). Additionally, in another test try to replaceAll("'","''") to escape it, preventing the code to break, but now it does not retrieve the expected row anymore and you end up with an empty report.
    Exception StackTrace:
    com.crystaldecisions.reports.exportinterface.exceptions.ExportException: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.formatter.a.c.if(Unknown Source)
    at com.crystaldecisions.reports.formatter.a.c.a(Unknown Source)
    at com.businessobjects.reports.sdk.b.b.int(Unknown Source)
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.x.a(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.q.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.dd.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.reports.sdk.PrintOutputController.export(Unknown Source)
    Caused by: com.crystaldecisions.reports.formatter.formatter.c: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.bv.<init>(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.bv.if(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.e.l.<init>(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.e.p.<init>(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.e.p.a(Unknown Source)
    at com.crystaldecisions.reports.formatter.a.c.a(Unknown Source)
    ... 17 more
    Caused by: com.crystaldecisions.reports.dataengine.be: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.dataengine.n.else(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.nr(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.bn(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.bp(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.else(Unknown Source)
    at com.crystaldecisions.reports.dataengine.s.a(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.a(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.aa(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.<init>(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.<init>(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.<init>(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.a(Unknown Source)
    ... 23 more
    Caused by: com.crystaldecisions.reports.reportdefinition.datainterface.n: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.reportdefinition.datainterface.p.a(Unknown Source)
    ... 35 more
    Caused by: com.crystaldecisions.reports.queryengine.driverImpl.m: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.queryengine.driverImpl.o.eC(Unknown Source)
    at com.crystaldecisions.reports.queryengine.driverImpl.o.if(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ap.ea(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ap.h(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ap.dV(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ax.if(Unknown Source)
    at com.crystaldecisions.reports.queryengine.bc.if(Unknown Source)
    at com.crystaldecisions.reports.queryengine.bc.do(Unknown Source)
    at com.crystaldecisions.reports.queryengine.bc.do(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ae.cy(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ae.cz(Unknown Source)
    at com.crystaldecisions.reports.queryengine.b1.bc(Unknown Source)
    ... 36 more
    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 's'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement$StatementExecutionRequest.executeStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(Unknown Source)
    ... 48 more
    - JRCAgent3 detected an exception: An error occured while exporting the report
    at com.businessobjects.reports.sdk.b.b.int(Unknown Source)
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.x.a(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.q.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.dd.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.reports.sdk.PrintOutputController.export(Unknown Source)

    Post Author: nl11087
    CA Forum: JAVA
    A single quote/apostrophe in string parameter passed to a Crystal Report with Command datasource connecting to a SQL Server database, using sqljdbc driver does not escape the special character correctly. When doing a preview in the Crystal Reports IDE it allows you to escape the input parameter as expected and work correctly, but through the JRC component it fails. For string parameters without special sql server characters I experience no problems at all. When replacing the Command with a direct table there is also no problem.
    Reproduction:
    1. create a database db1, create a table table1 with a String type column col1.
    2. Create new report Report1.rpt, create a connection to above, Add Command using 'SELECT col1, col2, col3 FROM table1 WHERE col1 = '{?Par1}' . Add a parameter field Par1 : String
    3. In your java stand alone application using JRC add the parameter Par1 with a value "Jon Doe's Value" containing a single apostrophe. Export to PDF. (I also tried MSWord and this failed too, similar behavior). Additionally, in another test try to replaceAll("'","''") to escape it, preventing the code to break, but now it does not retrieve the expected row anymore and you end up with an empty report.
    Exception StackTrace:
    com.crystaldecisions.reports.exportinterface.exceptions.ExportException: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.formatter.a.c.if(Unknown Source)
    at com.crystaldecisions.reports.formatter.a.c.a(Unknown Source)
    at com.businessobjects.reports.sdk.b.b.int(Unknown Source)
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.x.a(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.q.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.dd.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.reports.sdk.PrintOutputController.export(Unknown Source)
    Caused by: com.crystaldecisions.reports.formatter.formatter.c: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.bv.<init>(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.bv.if(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.e.l.<init>(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.e.p.<init>(Unknown Source)
    at com.crystaldecisions.reports.formatter.formatter.e.p.a(Unknown Source)
    at com.crystaldecisions.reports.formatter.a.c.a(Unknown Source)
    ... 17 more
    Caused by: com.crystaldecisions.reports.dataengine.be: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.dataengine.n.else(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.nr(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.bn(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.bp(Unknown Source)
    at com.crystaldecisions.reports.dataengine.n.else(Unknown Source)
    at com.crystaldecisions.reports.dataengine.s.a(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.a(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.aa(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.<init>(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.<init>(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.<init>(Unknown Source)
    at com.crystaldecisions.reports.dataengine.bk.a(Unknown Source)
    ... 23 more
    Caused by: com.crystaldecisions.reports.reportdefinition.datainterface.n: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.reportdefinition.datainterface.p.a(Unknown Source)
    ... 35 more
    Caused by: com.crystaldecisions.reports.queryengine.driverImpl.m: JDBC Error: Incorrect syntax near 's'.
    at com.crystaldecisions.reports.queryengine.driverImpl.o.eC(Unknown Source)
    at com.crystaldecisions.reports.queryengine.driverImpl.o.if(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ap.ea(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ap.h(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ap.dV(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ax.if(Unknown Source)
    at com.crystaldecisions.reports.queryengine.bc.if(Unknown Source)
    at com.crystaldecisions.reports.queryengine.bc.do(Unknown Source)
    at com.crystaldecisions.reports.queryengine.bc.do(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ae.cy(Unknown Source)
    at com.crystaldecisions.reports.queryengine.ae.cz(Unknown Source)
    at com.crystaldecisions.reports.queryengine.b1.bc(Unknown Source)
    ... 36 more
    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 's'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement$StatementExecutionRequest.executeStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(Unknown Source)
    ... 48 more
    - JRCAgent3 detected an exception: An error occured while exporting the report
    at com.businessobjects.reports.sdk.b.b.int(Unknown Source)
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.x.a(Unknown Source)
    at com.crystaldecisions.proxy.remoteagent.q.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.dd.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
    at com.crystaldecisions.reports.sdk.PrintOutputController.export(Unknown Source)

  • How to replace regex match into a char value (in the middle of a string)

    Hi uncle_alice and other great regex gurus
    One of my friends has a peculiar problem and I cant give him a solution.
    Using String#replaceAll(), i.e. NOT a Matcher loop, how could we convert matched digit string such as "65" into a char of its numeric value. That is, "65" should be converted into letter 'A'.
    Here's the failing code:
    public class GetChar{
      public static void main(String[] args){
        String orig = "this is an LF<#10#> and this is an 'A'<#65#>";
        String regx = "(<#)(\\d+)#>";
        //expected result : "this is an LF\n and this is an 'A'A"
        String result = orig.replaceAll(regx, "\\u00$2");
        // String result = orig.replaceAll(regx, "\\\\u00$2"); //this also doesn't work
        System.out.println(result);

    I don't know that we have lost anything substantial.i think its just that the kind of task this is
    especially useful for is kind of a blind-spot in the
    range of things java is a good-fit for (?)
    for certain tasks (eg process output munging) an
    experienced perl programmer could knock up (in perl)
    using built-in language features a couple of lines
    which in java could takes pages to do. If the cost is
    readability/maintainability/expandability etc.. then
    this might be a problem, but for a number of
    day-to-day tasks it isn't
    i'm trying to learn perl at the moment for this exact
    reason :)Yes. And when a Java source-code processor(a.k.a. compiler) sees the code like:
    line = line.replaceAll(regexp,  new String(new char[] {(char)(Integer.parseInt("$1"))}));or,
    line = line.replaceAll(regexp,  doMyProcessOn("$1")); //doMyProcess returns a Stringa common sense should have told him that "$1" isn't a literal string "$1" in this regular expression context.
    By the way, I abhor Perl code becaus of its incomprehensibleness. They can't be read by an average common sense. Java code can be, sort of ...

  • Replacing all occurrences of characters in a string with one new character?

    Hi there,
    I'm looking for a way that I could replace all occurrences of a set of specific characters with just one new character for each occurrence.
    For example if I have a string which is "word1...word2.......word3....word4............word5" how would I be able to replace this with just one character such as ":" for each set of "." so that it would essentially appear like this "word1:word2:word3:word4:word5"
    If I just use replace(".", ":") I am left with "word1:::word2:::::::word4::::word5::::::::::::"
    So therefore I'm guessing this would require the use of replaceAll() maybe? but I'm not really very familiar with how regular expressions work and how this would be accomplished using them.
    Any help would be greatly appreciated :) Thanks.

    Yes, but "." means any character, so ".\+" means "any character repeated more than once". If you just mean a full stop ("period" for you Americans :p) you should use "\.+" as your regular expression, but remember that for Java you need a '\' escape to recognise '\' as '\', so in code you'd actually type your regex as:
    "\\.+"Here's an example of one way to do it:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Test {
        public static void main(String[] args) {
           String string = "example1.......example2...example3.....example4";
         Pattern pattern = Pattern.compile("\\.+");
         Matcher stringMatcher = pattern.matcher(string);
         string = stringMatcher.replaceAll(":");
         System.out.println(string);
    }Edited by: JohnGraham on Oct 24, 2008 5:19 AM
    Edited by: JohnGraham on Oct 24, 2008 5:22 AM

  • Bug in replace all. escape characters are not working.

    Hi,
    My requirement is that whenever i see ":" (Colon) in the string then i want to replace it with (\:). So i tried
    String escapedTitle = "title:the world is not enough".replace(":", "\\:")
    and to my surprise, when i printed escapedTitle i got
    title\\:the world is not enough
    instead of
    title\:the world is not enough
    (note the back slash in the string)
    I want to ask why there is a different beehavious of escape characters? I am using JDK1.6.0_06

    Sorry for the last post. Please try this:
    public class test
    public static void main(String a[])
         String escapedTitle = "title:the world is not enough".replaceAll(":+", "\\:"); //or [:]+
         String escapedTitle1 = "title:the world is not enough".replaceAll(":+", "*"); // or [:]+
         System.out.println("Another String is "+ escapedTitle);
         System.out.println("Another String is "+ escapedTitle1);
         System.out.println(System.getProperty("java.vendor"));
         System.out.println(System.getProperty("java.version"));
    output is
    Another String is title:the world is not enough
    Another String is titlethe* world is not enough
    Sun Microsystems Inc.
    1.6.0_06
    Please let me know why i am not getting : as escaped (\:) with replaceAll method.
    i want string escapedTitle as Another String is title*\:*the world is not enough

  • Regex replaceAll question

    I am using replaceAll to replace a bunch of "tags" with content for this bit of software that I am porting (from something else) that creates documents (in the end) by populating templates with data.
    Here's my problem. The "tags" are all okay (not giving any regex content) but some of the data is. Because at first now I hit data that as a String has some regex funky characters in it. And regex got all all whiny about that because there aren't any matching groups. Well no. That's true.
    So I have to escape the $. But it occurs to me that I could well have more than this problem with other bits of content (including some parts I haven't gotten to yet) and I am wondering if there is any sort of easy solution. Is there way to tell replaceAll that the replacement String is a "literal" replacement i.e. I don't want any regex parsing at all just replace the found "tag" with the "content", that's it.
    Some sort of escape the whole sequence? Possibly. But I don't understand what it would be. \ is just for as single character?
    So any quick solution? Or alternative?
    BTW I am stuck with 1.4 on this project.

    yawmark wrote:
    I'd recommend trying Apache Commons StringUtils.
    Hope this message doesn't disappear into the aether.
    ~I think it did for awhile but like Lazarus arose...
    Anyway thank you for the effort.
    This is an interesting suggestion but I'd rather not go the route of adding more libraries.
    What I did at first was
    private void replaceAll(StringBuffer buff, String toFind, String toReplace){
      while(buff.indexOf(toFind)>-1){
         buff.replace(buff.indexOf(toFind),buff.indexOf(toFind)+toFind.length(),toReplace);
    }which worked good enough for me but someone else pointed out quoteReplacement and just doing my own version of that. Which works well too.
    Anyway thanks again I do appreciate it what with the current situation and all.

Maybe you are looking for

  • How can I remove a device from my iCloud/Apple ID?

    Hi, I merged my dad's iphone to my Apple ID a while back because he wants to buy an app and I have some credit left over so I let him used my ID on his device. Apparently, all my contacts, pictures from photo stream, and ical are now also in his devi

  • RFC destination error while importing a client request

    Dear Experts, We are trying to import a Client Export from our Prd system to Development System and we are unable to import the request as it pops up a RFC destination error. We have checked the RFC in the Dev QAS and PRD related to TMSADM and all of

  • Macbook pro crashes in sleep mode ALL the time - with LOG. HELP!

    Hi there, My macbook pro 13' intel 2.26 5 GB RAM, currently running Mac Os Lion 10.7.1 constantly crashes when going to sleep mode. This happens regardless of the lid being closed or not. Here's the log from the last crash.. hope it helps anyone givi

  • Uploading photo gallery to a Mac?

    I have an original Facinate and have just ordered an iPhone 5 upgrade. I have two years of images on the phone that I don't want to lose. How cna I uploade these images to my Mac desktop? Thanks

  • Old Mac games not working

    I've just found a box with some of my favourite old Mac games in that I used with my old Lime iMac. Titles such as FA/18 Hornet, Command and Conquer and Railroad Tycoon amongst others. I also have some education disks that are invaluable resources. I