 ShowAll Questionssorted byDate Posted Awe Awe

# apex extra or split the string

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 Best Answer chosen by Awe Awe mukesh gupta
HI Awe,

```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 mukesh gupta
HI Awe,

```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

This was selected as the best answer Awe Awe Awe Awe