Salesforce 在顶点中连接字符串数组

Salesforce 在顶点中连接字符串数组,salesforce,apex-code,Salesforce,Apex Code,使用Apex,我想拆分一个字符串,然后用and运算符作为分隔符重新连接它 我成功地拆分了字符串,但在重新加入时遇到了问题 String [] ideaSearchText = searchText.Split(' '); // How to rejoin the array of strings with 'AND'? 如何执行此操作?从v26(冬季13)开始,您可以通过将字符串[]传递给来执行此操作 匿名Apex输出调用系统调试(结果): 21:02:32.039(39470000)|开

使用Apex,我想拆分一个字符串,然后用and运算符作为分隔符重新连接它

我成功地拆分了字符串,但在重新加入时遇到了问题

 String [] ideaSearchText = searchText.Split(' ');
 // How to rejoin the array of strings with 'AND'?
如何执行此操作?

从v26(冬季13)开始,您可以通过将
字符串[]
传递给来执行此操作

匿名Apex输出调用系统调试(结果):

21:02:32.039(39470000)|开始执行|
21:02:32.039(39485000)|代码|单元|启动|[外部]|执行|匿名|
21:02:32.040(40123000)|系统|构造函数|[3]|()
21:02:32.040(40157000)|系统|建造商|出口|[3]|()
21:02:32.040(40580000)|用户|调试|[5]|调试|值一和值二和值三

Salesforce API文档:

注意,如果字符串对象太大,则会出现异常
Regex太复杂
。在这种情况下,您可以执行以下操作:

Blob blobValue = (Blob)record.get(blobField);

// Truncate string then split on newline, limiting to 11 entries
List<String> preview = blobValue.toString().substring(0,1000).split('\n', 11);

// Remove the last entry, because The list’s last entry contains all 
// input beyond the last matched delimiter.
preview.remove(preview.size()-1);

// In my use-case, I needed to return a string, and String.join() works 
// as the reverse of split()    
return String.join(preview, '\n');
Blob blobValue=(Blob)record.get(blobField);
//截断字符串,然后在换行符上拆分,限制为11个条目
列表预览=blobValue.toString().substring(01000).split('\n',11);
//删除最后一个条目,因为列表的最后一个条目包含所有
//输入超出最后匹配的分隔符。
preview.remove(preview.size()-1);
//在我的用例中,我需要返回一个字符串,string.join()可以工作
//与split()相反
返回字符串。join(预览“\n”);

非常感谢您的回答。它帮助我走出了困境。此外,它真的很有意义,并且让我更好地理解了哪些实现选择会增加堆的大小?
21:02:32.039 (39470000)|EXECUTION_STARTED
21:02:32.039 (39485000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
21:02:32.040 (40123000)|SYSTEM_CONSTRUCTOR_ENTRY|[3]|<init>()
21:02:32.040 (40157000)|SYSTEM_CONSTRUCTOR_EXIT|[3]|<init>()
21:02:32.040 (40580000)|USER_DEBUG|[5]|DEBUG|valueOne AND valueTwo AND valueThree
Blob blobValue = (Blob)record.get(blobField);

// Truncate string then split on newline, limiting to 11 entries
List<String> preview = blobValue.toString().substring(0,1000).split('\n', 11);

// Remove the last entry, because The list’s last entry contains all 
// input beyond the last matched delimiter.
preview.remove(preview.size()-1);

// In my use-case, I needed to return a string, and String.join() works 
// as the reverse of split()    
return String.join(preview, '\n');