+ Start a Discussion

Ascii Characters with in Apex class


How can get the ascii characters with in apex class?


If i took 'A' i need to get the ascii value of that character : 65

char text='A';

system.debug(); // i need to 65 here.






Best Answer chosen by Admin (Salesforce Developers) 
Ankit AroraAnkit Arora

I am able to find out the way to fetch the ASCII code in javascript, so using the below code you can send ASCII code of any string in apex class. Here is the code :




<apex:page id="pg" controller="MyAsciiClass">

  <apex:form id="frm">
      <apex:pageBlock id="pb">
          <apex:outputText id="IH" value="{!MyAsciiCode}"/>

    var myAsciiCode = '' ;
    function thisFunction()
        var someString = "Hopper";
        var j;
        for(j = 0; j < someString.length; j++)
            if(myAsciiCode == '')
                myAsciiCode += someString.charCodeAt(j);
                myAsciiCode += ',' + someString.charCodeAt(j);
        document.getElementById('pg:frm:pb:IH').innerHTML = myAsciiCode ;
    thisFunction() ;


Class :


public class MyAsciiClass
    public String MyAsciiCode {get; set;}
    public MyAsciiClass()
        MyAsciiCode = '' ;


ASCII code is displayed comma separated. You can parse this string in apex code easily. Let me know if face any other issue.




Ankit Arora

Blog | Facebook | Blog Page