I want to replace Or, or, OR, oR to "||"
validationExpr = validationExpr.replaceAll('(?i)or', ' \\|\\| '); The result will be ||
How could we do this in Apex? Thanks
I want to replace Or, or, OR, oR to "||"
validationExpr = validationExpr.replaceAll('(?i)or', ' \\|\\| '); The result will be ||
How could we do this in Apex? Thanks
I think you will get || in debug log because Salesforce uses |character as a separator in debug logs however in real time application, it will work as expected.
Example:
20:59:52.14 (15076267)|STATEMENT_EXECUTE|[2] 20:59:52.14 (15083284)|HEAP_ALLOCATE|[2]|Bytes:6 20:59:52.14 (15087825)|HEAP_ALLOCATE|[2]|Bytes:6 20:59:52.14 (15149679)|HEAP_ALLOCATE|[2]|Bytes:12 20:59:52.14 (15167781)|VARIABLE_ASSIGNMENT|[2]|validationExpr|"hey || hey" I created a sample VF pg to test this:
VF page code:
<apex:page controller="TestClass"> {!strData} <hr/> {!strData2} </apex:page> Class Code:
public class TestClass { public String strData{get;set;} public String strData2{get;set;} public TestClass(){ strData = '||'; strData2 = 'Hello or Hi OR Hola'.replaceAll('(?i)or', ' \\|\\| '); } } Result: