for(String line : lines){
i++;
if(skipFirst && i <= 1) continue;
if(isBlank(line)) return error('Line ' + i + ' blank');
pattern regex=pattern.compile(',(?=([^"]*"[^"]*")*[^"]*$)');
cells=regex.split(line);
string tmp0=cells.get(1).replace('"','');
if(cells == null || cells.size() < 2) return error('Line ' + i + ' is either blank or contains only one cell');
code = cells.get(0);
if(code != null) code = code.trim();
try{
//If the amount is empty or null, assume it is 0
if(cells.get(1) == null || cells.get(1) == ''){
amount = 0;
}
else{
if(!cells.get(1).contains('"')){
amount = Decimal.valueOf(cells.get(1));
}else{
string tmp=cells.get(1).replace('"','');
amount = Decimal.valueOf(tmp.replace(',',''));
}
}
}catch(System.TypeException e){
return error('Line ' + i + ' contains invalid amount');
}
values.put(code,amount);
}
这篇文章是为了后代,因为我确实在salesforce内部使用正则表达式找到了一个解决方案……但是它很长而且可能没有必要。