• Maria H 5
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
i have 3 fields 
field 1- mr
field 2- bean
in the field 3 i have to show 'mr bean '
basically i have to show the 2 fields value in the 3rd field

The output of the Apex String.format function doesn't seem correct when the format string contains an escaped single quote.

 

E.g. Executing the following Anonymous code in Eclipse

 

 

String formattedString = String.format('Hello {0}, \' shall we play a {1}', new String[]{'David', 'game'});
System.debug(formattedString);
System.debug('before \' after');

 

 

System.debug(formattedString) results in
Hello David,  shall we play a {1}

 

Rather than the expected

Hello David, ' shall we play a game

 

Is this a bug/feature of String.format?

 

I've had a colleague reproduce this issue in a separate install of Eclipse and also seen it with a Chatter FeedPost created by a trigger.