-1

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

3
  • Are you trying to get || or ||? Commented Feb 10, 2018 at 2:56
  • 1
    What behavior do you observe, and how does it diverge from your expected behavior? Commented Feb 10, 2018 at 17:45
  • the below response answered my question. thank you Commented Feb 12, 2018 at 17:41

1 Answer 1

4

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:

Result

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.