function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HAZLITT VASUDEVANHAZLITT VASUDEVAN 

how to get output nextline?

String a = 'Hello. \n Welcome to salesforce, \n Name \n Asian Paints \n WO Number \n 12345678 \n Account Id \n 1547586597';
        List<String> lst = new List<String>();
        lst=a.split('\n');
        System.debug(lst);

output I got in a same line with a comma.
Best Answer chosen by HAZLITT VASUDEVAN
Maharajan CMaharajan C
Hi Hazlitt, 

Instead of  \n you can directly use the  \r\n  in String.
String a = 'Hello. \r\n Welcome to salesforce, \r\n Name \r\n Asian Paints \r\n WO Number \r\n 12345678 \r\n Account Id \r\n 1547586597';

system.debug(' a ==> ' + a);

( OR  you can use the below code )
 
String a = 'Hello. \n Welcome to salesforce, \n Name \n Asian Paints \n WO Number \n 12345678 \n Account Id \n 1547586597';
List<String> lst = new List<String>();
lst=a.split('\r\n');
System.debug(lst);

Thanks,
Maharajan.C

 

All Answers

CharuDuttCharuDutt
Hii Hazlitt
Try Below Code
String a = 'Hello. \n Welcome to salesforce, \n Name \n Asian Paints \n WO Number \n 12345678 \n Account Id \n 1547586597';
        List<String> lst = new List<String>();
            
        lst=a.split('\n');
for(integer i=0;i<lst.Size();i++){
    System.debug(lst[i]);
}
Please Mark It As Best Answer If It Helps
Thank You!

 
Maharajan CMaharajan C
Hi Hazlitt, 

Instead of  \n you can directly use the  \r\n  in String.
String a = 'Hello. \r\n Welcome to salesforce, \r\n Name \r\n Asian Paints \r\n WO Number \r\n 12345678 \r\n Account Id \r\n 1547586597';

system.debug(' a ==> ' + a);

( OR  you can use the below code )
 
String a = 'Hello. \n Welcome to salesforce, \n Name \n Asian Paints \n WO Number \n 12345678 \n Account Id \n 1547586597';
List<String> lst = new List<String>();
lst=a.split('\r\n');
System.debug(lst);

Thanks,
Maharajan.C

 
This was selected as the best answer
HAZLITT VASUDEVANHAZLITT VASUDEVAN
Thanks for responding @Maharajan C @CharuDutt