Replace function in String using Apex in Salesforce

Replace function in String using Apex in Salesforce

Simple Replace Code:

String str = 'RAM';
System.debug( 'Replace value is ' + str.replace( 'A', 'O' ) );

Output:

Sample Multi-Level or multiple characters replace Code:

String str = 'test';
System.debug( 'Replace value is ' + str.replace( 't', '$' ).replace( 'e', '*' ).replace( 's', '%' ) );

Output:

Leave a Reply