function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pavan kumar vpavan kumar v 

Extract Specific string and add a new word after it

Can anyone guide me on this to tackle this.
String aa = ‘hey how you’;
String bb = aa.contains(‘are’); // I need to extract ‘how’ from aa and place it in a new string bb.
Then I need to ADD a NEW word ‘are’ after the word ‘how’
So finally the sentence would be ‘ hey how are you’ .
Can anyone please guide me on this
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Pavan,

Can you check the below code.
 
String string1='hey how you';
String String2=' are ';
String newString = 
    String1.substring(0, String1.indexOf('you')) +
    String2 + 
    String1.substring(String1.indexOf('you'), String1.length());
system.debug('string result' +newString);

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,