无法从字符串中删除最后一个逗号

时间:2013-05-08 02:14:59

标签: apex-code

我正在尝试使用substring方法删除字符串中的最后一个逗号:

system.debug('******************* quoteQuery ' + quoteQuery);
quoteQuery = quoteQuery.subString(0,quoteQuery.Length()-1);
system.debug('******************* quoteQuery ' + quoteQuery);

这是字符串调试输出:

DEBUG|******************* quoteQuery SELECT phone,  lineitemcount,  additionalstreet,  expirationdate,  shippingname,  contactid,  createdbyid,  shippinghandling,  additionalstate,  billingcity,  description,  isdeleted,  quotetostate,  quotenumber,  systemmodstamp,  fax,  totalprice,  status,  quotetocountry,  shippingcity,  quotetopostalcode,  billingpostalcode,  shippingstate,  createddate,  subtotal,  discount,  tax,  email,  shippingpostalcode,  lastmodifiedbyid,  additionalcountry,  billingstate,  billingcountry,  lastmodifieddate,  id,  name,  pricebook2id,  shippingstreet,  opportunityid,  quotetocity,  additionalpostalcode,  billingname,  additionalcity,  shippingcountry,  additionalname,  grandtotal,  billingstreet,  issyncing,  quotetoname,  quotetostreet, 

最后一个逗号没有删除?

感谢任何帮助。 感谢。

1 个答案:

答案 0 :(得分:1)

这将返回完整的字符串

quoteQuery.subString(0,quoteQuery.Length()-1);

而不是Lenght()-1尝试Length()-2

quoteQuery = quoteQuery.subString(0,quoteQuery.Length()-2);