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
BrabasBrabas 

equivalent char(Ascii) function?

Hello,

 

I was wondering if there is any equivalent string function that can used similar to the char(Ascii) function which exists in java? ejp. char(39) = ' in Ascii

 Component.Apex.inputText it_dEPolicy=new Component.Apex.inputText ();

it_dEPolicy.onmouseover='initialiseCalendar(this,'+char(39)+'{!$Component.dEPolicy}'+char(39)+')';

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You have to escape literal apostrophes it by preceding it with a backslash, as follows:

 

'You can\'t believe it\'s not butter!'

 

All Answers

sfdcfoxsfdcfox
public static String fromCharCode( integer x ) {
  return String.fromCharArray( new integer[] { x } );
}

You can use this utility function using the newly added string functions in Winter 13 or so. Use it like this:

 

it_dEPolicy.onmouseover='initialiseCalendar(this,'+fromcharcode(39)+'{!$Component.dEPolicy}'+fromcharcode(39)+')';

If using it from a utility class, make sure you call it using the class' name.

BrabasBrabas

the problem is that I find ways to contain the tilde in a variable, the function char (39) returns the Java tilde (') in apex not find a way to contain the tilde, without closing the expression.

sfdcfoxsfdcfox

You have to escape literal apostrophes it by preceding it with a backslash, as follows:

 

'You can\'t believe it\'s not butter!'

 

This was selected as the best answer
BrabasBrabas

 Thank you for you help, I changed my controller to be like this:

 
it_dEPolicy.onmouseover='initialiseCalendar(this,\'idp:idf:j_id12_0:j_id12_4:dEPolicy\')';