Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to split an apex string into smaller chunks?

Asked by Claudine Tippins Mar 2, 2023 992 views 1 answer
Share

About this question

 I have a requirement where I need to split a string into a list of substrings with size 2 that is for example,


String = 'ABCDEF J4' and I want the output as
List subStringList = {'AB', 'CD', 'EF','J4'}
I have tried it in javascript with the following :
var chunkStr = function(str, chunkLength) {
    return str.match(new RegExp('[\s\S]{1,' + +chunkLength + '}', 'g'));
}  

I am not sure how to achieve the same in apex. Could someone please point me in the right direction.

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.