samedi 25 avril 2015

replacing the carriage return with white space in java


I am having the below string in a string variable in java.

rule "6"
no-loop true
    when
    then
    String prefix = null;
    prefix = "900";
    String style = null;
    style = "490";
    String  grade = null;
    grade = "GL";
    double basePrice = 0.0;
    basePrice = 837.00;
    String ruleName = null;
    ruleName = "SIVM_BASE_PRICE_006
Rahul Kumar Singh";
    ProductConfigurationCreator.createFact(drools, prefix, style,grade,baseprice,rulename);
end
rule "5"
no-loop true
    when
    then
    String prefix = null;
    prefix = "800";
    String style = null;
    style = "481";
    String  grade = null;
    grade = "FL";
    double basePrice = 0.0;
    basePrice = 882.00;
    String ruleName = null;
    ruleName = "SIVM_BASE_PRICE_005";
    ProductConfigurationCreator.createFact(drools, prefix, style,grade,baseprice,rulename);
end

I need to replace this the carriage return between "THEN" and "END" keyword with white space so that it becomes like below code:

rule "6"
no-loop true
    when
    then
    String prefix = null;
    prefix = "900";
    String style = null;
    style = "490";
    String  grade = null;
    grade = "GL";
    double basePrice = 0.0;
    basePrice = 837.00;
    String ruleName = null;
    ruleName = "SIVM_BASE_PRICE_006 Rahul Kumar Singh";
    ProductConfigurationCreator.createFact(drools, prefix, style,grade,baseprice,rulename);
end

rule "5"
no-loop true
    when
    then
    String prefix = null;
    prefix = "800";
    String style = null;
    style = "481";
    String  grade = null;
    grade = "FL";
    double basePrice = 0.0;
    basePrice = 882.00;
    String ruleName = null;
    ruleName = "SIVM_BASE_PRICE_005";
    ProductConfigurationCreator.createFact(drools, prefix, style,grade,baseprice,rulename);
end

In the above two example of string set, the second is correct format that I need. However, in the first set, I am getting this :

ruleName = "SIVM_BASE_PRICE_006
Rahul Kumar Singh";

This perticulerly needs to be like this:

ruleName = "SIVM_BASE_PRICE_006 Rahul Kumar Singh";

and I also need to ensure that this doesn't effect any thing else in the string. Thus I need to replace this "carriage return" with a white space and make in one line. This is my requirment. I tried with replace and replaceAll method of string but not works properly.

Problem:

I need to look in between string "then" and "end" and in that whenever there is any carriage return in between two double quaotes "" ""; I need to replace this carriage return with white space and make it in one line.

Thanks

EDIT:

DRT:

template header
Prefix
Style
Product

package com.xx
import com.xx.drools.ProductConfigurationCreator;

template "ProductSetUp"
rule "Product_@{row.rowNumber}"
no-loop true
    when
    then
      String prefix = null;
      prefix = "@{Prefix}";
      String style = null;
      prefix = "@{Style}";
      String product = null;
      product = "@{Product}";
      ProductConfigurationCreator.createProductFact(drools,prefix,style,product);
end
end template

The excel and drt are for only demostration purpose. In the Image, in Product column, there is "SOFAS \rkumar shorav". Actually this is creating problem. This will generate like below:

product = "SOFAS
kumar shorav";

I need this like below:

product = "SOFAS kumar shorav";

Then Excel data :

attached image.enter image description here


Aucun commentaire:

Enregistrer un commentaire