Skip to main content
hi how can i achieve this

//id

String a = '111,112,113,114 etc';

//my ouput should like this

String Result1 = 111,112,113

String Result2 = 113,114 etc

 
3 answers
  1. Apr 13, 2022, 6:05 AM
    HI Awe,

    Please use below code:-

    String a = '111,112,113,114 etc';

    String[] lst = a.split(',');

    String result1;

    String result2;

    System.debug('lst.size()== '+lst.size());

    for(Integer i = 0; i<lst.size() ; i++){

    if(i < 3){

    if(i == 0){

    result1 = lst[i];

    }

    if(i> 0 && i<3){

    result1 += ','+lst[i];

    }

    if( i== 2){

    result2 = lst[i];

    }

    }else{

    if(i== 3){

    result2 += ','+lst[i];

    }

    }

    }

    system.debug('result1 '+result1);

    system.debug('result2 '+result2);

    if you need any assistanse, Please let me know!!

    Kindly mark my solution as the best answer if it helps you.

    Thanks

    Mukesh 

     
0/9000