regex - replacing the carriage return with white space in java -
i having below string in string variable in java.
rule "6" no-loop true when 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 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 replace carriage return between "then" , "end" keyword white space becomes below code:
rule "6" no-loop true when 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 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 above 2 example of string set, second correct format need. however, in first set, getting :
rulename = "sivm_base_price_006 rahul kumar singh"; this perticulerly needs this:
rulename = "sivm_base_price_006 rahul kumar singh"; and need ensure doesn't effect thing else in string. need replace "carriage return" white space , make in 1 line. requirment. tried replace , replaceall method of string not works properly.
problem:
i need in between string "then" , "end" , in whenever there carriage return in between 2 double quaotes "" ""; need replace carriage return white space , make in 1 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 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 , drt demostration purpose. in image, in product column, there "sofas \rkumar shorav". creating problem. generate below:
product = "sofas kumar shorav"; i need below:
product = "sofas kumar shorav"; then excel data :
attached image.
you might there bug in org.drools.template.parser.stringcell, method
public void addvalue(map<string, object> vars) { vars.put(column.getname(), value); } here, value added map string not take account string values expanded string literals. therefore, embedded newline should converted escape sequence \n. might try patch:
public void addvalue(map<string, object> vars) { string h = value.replaceall( "\n", "\\\\n" ); vars.put(column.getname(), h); } take source file, put suitable subdirectory, compile class file , make sure root directory precedes drools-templates-6.2.0.final-sources.jar in class path. should see
rulename = "sivm_base_price_006\nrahul kumar singh"; in generated drl file. obviously, not space, but written in spreadsheet cell!
i suggest (urgently) do not follow approach. reason strings not always expanded between quotes, , replacement result in invalid code. there no remedy template compiler "dumb" , not "know" expanding.
if string in spreadsheet contains line break, template expansion must render faithfully, , break line there. if produces invalid (java) code: why line break entered in first place? there absolutely no reason not have space in cell if that's want.