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
magsy1.3942130065717605E12magsy1.3942130065717605E12 

How to remove single quote from end of string using escapeSingleQuotes

Hi,

I am new to Salesforce and therefore want to know the exact functioning of escapeSingleQuotes() method.
My code uses this method as:

soql = 'Select Id, Name, Metals__c from Smelter__c where';
        soql += ' Name LIKE \''+String.escapeSingleQuotes(smelterNameQuery.trim())+'%\'';

The name consists of single quote at the end of string.
So how do I remove the single quote.?
Chaten Raghav 9Chaten Raghav 9
Hi,

Here is the Sample code which you can use to remove the ',' if there is any at the end of your string.
================================================
string teststring = 'Myteststring,'   ;
   if(teststring.endsWith(','))
      
   {teststring= teststring.substring(0,teststring.length()-1);
       system.debug('>>>>>>>>>>' + teststring);
   }
=================================================
Also, you can review the String methods at http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_methods_system_string.htm
Please Mark it as the ""Best Answer"" if it works for you.
  
Thanks.
Chaten Raghav