Error
This content is not currently supported on this browser.
+ Start a Discussion
SFDC_LearnerSFDC_Learner 

Ascii Characters with in Apex class

Hi,

How can get the ascii characters with in apex class?

Ex:

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 :

 

VFP :

 

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

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

<script>
    var myAsciiCode = '' ;
    function thisFunction()
    {
        var someString = "Hopper";
        var j;
        for(j = 0; j < someString.length; j++)
        {
            if(myAsciiCode == '')
                myAsciiCode += someString.charCodeAt(j);
            else
                myAsciiCode += ',' + someString.charCodeAt(j);
        }
        document.getElementById('pg:frm:pb:IH').innerHTML = myAsciiCode ;
    }
    thisFunction() ;
</script>
  
</apex:page>

 

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.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page