fork download
import java.util.*; 
class ChangeTextProgram {
 
  public static void main(String[] args) { 
 
String str = "  ('HE191','Principles of Economics','1','SCE',3,300,'One 2-hr Lecture'),('HW0001','English Proficiency','1','SCE',0,200,'To be conducted by HSS'),('HW0110','Effective Communication','1','SCE',2,150,'No Tutorial and Lab'),('HW110','Effective Communication','2','SCE',2,300,''),('HW210','Technical Communications','2','SCE',2,300,''),('HW310','Professional Communication','3','SCE',2,300,''),('CE8003','HRM & Entrepreneurship','1','CE',3,150,'Shared code with CPE/CSC184'),('CE9002','How Computers Work','1','SCE',4,90,'Same as CM102'),('CE9003','Applying IT','1','SCE',4,90,'Same as CM103'),('HE9091','Principles of Economics','1','SCE',4,300,''),('HW0210','Technical Communications','2','SCE',2,300,''),('HW0310','Professional  Comm','3','SCE',2,300,''),('CE0001','Engineers and Society','1','CE',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183'),('CZ0001','Engineers and Societ','1','CSC',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183')";
 /*,('HE191','Principles of Economics','1','SCE',3,300,'One 2-hr Lecture, One 1-hr Tutorial weekly'),('HW0001','English Proficiency','1','SCE',0,200,'To be conducted by HSS'),('HW0110','Effective Communication','1','SCE',2,150,'No Tutorial and Lab'),('HW110','Effective Communication','2','SCE',2,300,''),('HW210','Technical Communications','2','SCE',2,300,''),('HW310','Professional Communication','3','SCE',2,300,''),('CE8003','HRM & Entrepreneurship','1','CE',3,150,'Shared code with CPE/CSC184'),('CE9002','How Computers Work','1','SCE',4,90,'Same as CM102'),('CE9003','Applying IT','1','SCE',4,90,'Same as CM103'),('HE9091','Principles of Economics','1','SCE',4,300,''),('HW0210','Technical Communications','2','SCE',2,300,''),('HW0310','Professional  Comm','3','SCE',2,300,''),('CE0001','Engineers and Society','1','CE',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183'),('CZ0001','Engineers and Societ','1','CSC',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183')
 ('CE1001','Discrete Mathematics','1','CE',3,150,'Code share with CZ1001 and Cxx106'),('CE1002','Introduction to Computing Systems','2','CE',3,80,'Poly exempted. Code shared with CSC101'),('CE1003','Introduction to Computational Thinking','1','CE',3,150,''),('CE1004','Great Ideas in Computing','1','CE',2,150,'1 HOUR OF LECTURE PER WEEK'),('CE1005','Digital Logic','1','CE',3,150,''),('CE1008','Engineering Mathematics','1','CE',3,110,'Code shared with Cxx103'),('CE8001','Engineers and Society','1','CE',3,70,'No Lab. Taken by Poly only in CE1 semester 1'),('CM101','Java and Internet','1','SCE',4,90,''),('CM102','How Computers Work','1','SCE',4,90,''),('CM103','Applying IT','1','SCE',4,90,''),('CPE101','Electronics Principles','1','CE',4,90,''),('CPE102','Introduction to Programming','1','CE',4,90,''),('CPE103','Mathematics I','1','CE',4,90,''),('CPE104','Logic Design','1','CE',4,90,''),('CPE105','Data Structures and Object-Oriented Prog','1','CE',4,90,''),('CPE106','Mathematics II','1','CE',4,90,''),('CPE183','Engineers & Society','1','CE',4,90,''),('CPE184','HR Management & Entrepreneurship','1','CE',4,90,''),('CPE201','Digital Circuits & Systems','2','CE',4,90,''),('CPE202','Computer Organisation','2','CE',4,90,''),('CPE203','Software Systems and Models','2','CE',4,90,''),('CPE204','Discrete Mathematicss and Algorithms','2','CE',4,90,''),('CPE205','Operating Systems','2','CE',4,90,''),('CPE206','Microprocessor Systems Design','2','CE',4,90,''),('CPE207','Software Engineering','2','CE',4,90,''),('CPE208','Instrumentation and Data Acquisition','2','CE',4,90,''),('CPE301','Digital Communication','3','CE',4,90,''),('CPE302','Computer Networks','3','CE',4,90,''),('CPE303','Database Systems','3','CE',4,90,''),('CPE401','Advanced Algorithms','4','CE',4,90,''),('CPE402','Advanced Computer Networks','4','CE',4,90,''),('CPE404','Advanced Microprocessor Systems','4','CE',4,90,''),('CPE406','Artificial Intelligence','4','CE',4,90,''),('CPE409','Computer Architecture','4','CE',4,90,''),('CPE410','Computer Game Programming','4','CE',4,90,''),('CPE411','Computer Graphics and Applications','4','CE',4,90,''),('CPE413','Cryptography and Network Security','4','CE',4,90,''),('CPE419','Introductory Bioinformatics','4','CE',4,90,''),('CPE422','Neural Networks','4','CE',4,90,''),('CPE423','Parallel Processing','4','CE',4,90,''),('CPE424','Principles of Information Theory and Coding','4','CE',4,90,''),('CPE425','Programming Languages','4','CE',4,90,''),('CPE426','Real-Time Systems','4','CE',4,90,''),('CPE432','Visualisation','4','CE',4,150,''),('CPE805','Entering the Spiders Web: Imlpications & Issues','8','CE',4,90,''),('CSC101','Introduction to Computer Systems','1','CS',4,90,''),('CSC102','Introduction to Programming','1','CS',4,90,''),('CSC103','Mathematics I','1','CS',4,90,''),('CSC104','Logic Design','1','CS',4,90,''),('CSC105','Data Structures and Object-Oriented Prog','1','CS',4,90,''),('CSC106','Discrete Mathematics','1','CS',4,90,''),('CSC183','Engineers & Society','1','CS',4,90,''),('CSC184','HR Management & Entrepreneurship','1','CS',4,90,''),('CSC201','Computer Organisation','2','CS',4,90,''),('CSC202','Algorithms','2','CS',4,90,''),('CSC203','Software Systems and Models','2','CS',4,90,''),('CSC204','Computer Graphics in Design','2','CS',4,90,''),('CSC205','Operating Systems','2','CS',4,90,''),('CSC206','Database Systems','2','CS',4,90,''),('CSC207','Software Engineering I','2','CS',4,90,''),('CSC301','Programming Languages','3','CS',4,90,''),('CSC302','Net Centric Computing','3','CS',4,90,''),('CSC303','Software Engineering II','3','CS',4,90,''),('CSC304','AI and Intelligent Systems','3','CS',4,90,''),('CSC401','Advanced Algorithms','4','CS',4,90,''),('CSC402','Advanced Computer Networks','4','CS',4,90,''),('CSC406','Computer Architecture','4','CS',4,90,''),('CSC407','Computer Game Programming','4','CS',4,90,''),('CSC409','Cryptography and Network Security','4','CS',4,90,''),('CSC417','Introductory Bioinformatics','4','CS',4,90,''),('CSC421','Natural Language Processing','4','CS',4,50,''),('CSC422','Neural Networks','4','CS',4,90,''),('CSC423','Parallel Processing','4','CS',4,90,''),('CSC427','Visualisation','4','CS',4,100,''),('CZ1001','Discrete Mathematics','2','CSC',3,240,'Code shared with Cxx106'),('CZ1002','Introduction to Computing Systems','1','CSC',3,240,'POLY EXAMPTED. Code shared CSC101'),('CZ1003','Introduction to Computational Thinking','1','CSC',3,240,''),('CZ1004','Great Ideas in Computing','1','CSC',2,240,'1 HOUR OF LECTURE PER WEEK'),('CZ1005','Digital Logic','1','CSC',3,240,''),('CZ1008','Engineering Mathematics','1','CSC',3,100,''),('CZ8001','Engineers and Society','1','CSC',3,240,'For Poly only. Code shared with Cxx183')*/
 String lastString = "";
 String semiFinal="";
Scanner input = new Scanner(str);
 
 String delistr = "\\)";
input.useDelimiter(delistr);
 
while(input.hasNext()){
      String frontstring=input.next();
       System.out.println("Front string: " + frontstring );
      String afterRemove3Char = frontstring.substring(3);
       System.out.println("Remove 3 char: " + afterRemove3Char);
         
      Scanner data = new Scanner(afterRemove3Char);
      data.useDelimiter(",");
      
      while(data.hasNext()){
          String code = data.next();
          System.out.println("code:" +code); 
          
          String name = data.next();
          System.out.println("name:" +name);
          
          String year = data.next();
          System.out.println("year:" +year);
          
          String discipline = data.next();
          System.out.println("discipline:" +discipline);

          String acad_unit = data.next();
          System.out.println("acad_unit:" +acad_unit);
          
          String cohort_size = data.next();
          System.out.println("cohort_size:" +cohort_size);
          
          String remarks = data.next();
          System.out.println("remarks:" +remarks);          
          
          /*  attr_accessible :acad_unit, /
                  :cohort_size, /
                  :discipline, /
                  :remarks, /
                  :subject_code, /
                  :subject_name, /
                  :year_of_study, /
                  :lessons_attributes #foreign*/
          
          /*  {venue_name: 'C&I', venue_type: 'Lab', capacity: 80, remarks: 'Control and Instrumentation'}, 
            {subject_code: code, subject_name: name, year_of_study: year, discipline: discipline, acad_unit:acad_unit, cohort_size: cohort_size, remarks: remarks}, */
            
            semiFinal = "{subject_code: " +code + ", subject_name: " +name + ", year_of_study: " +year + ", discipline: " +discipline + ", acad_unit: " +acad_unit + ", cohort_size: " +cohort_size + ", remarks: " + remarks + "},";
            System.out.println(semiFinal);
    }
      
      lastString = lastString + semiFinal;
      
      System.out.println(); 
 
 }
 
 System.out.println(lastString);
 
}
 
}
Success #stdin #stdout 0.34s 61768KB
stdin
Standard input is empty
stdout
Front string:   ('HE191','Principles of Economics','1','SCE',3,300,'One 2-hr Lecture'
Remove 3 char: 'HE191','Principles of Economics','1','SCE',3,300,'One 2-hr Lecture'
code:'HE191'
name:'Principles of Economics'
year:'1'
discipline:'SCE'
acad_unit:3
cohort_size:300
remarks:'One 2-hr Lecture'
{subject_code: 'HE191', subject_name: 'Principles of Economics', year_of_study: '1', discipline: 'SCE', acad_unit: 3, cohort_size: 300, remarks: 'One 2-hr Lecture'},

Front string: ,('HW0001','English Proficiency','1','SCE',0,200,'To be conducted by HSS'
Remove 3 char: HW0001','English Proficiency','1','SCE',0,200,'To be conducted by HSS'
code:HW0001'
name:'English Proficiency'
year:'1'
discipline:'SCE'
acad_unit:0
cohort_size:200
remarks:'To be conducted by HSS'
{subject_code: HW0001', subject_name: 'English Proficiency', year_of_study: '1', discipline: 'SCE', acad_unit: 0, cohort_size: 200, remarks: 'To be conducted by HSS'},

Front string: ,('HW0110','Effective Communication','1','SCE',2,150,'No Tutorial and Lab'
Remove 3 char: HW0110','Effective Communication','1','SCE',2,150,'No Tutorial and Lab'
code:HW0110'
name:'Effective Communication'
year:'1'
discipline:'SCE'
acad_unit:2
cohort_size:150
remarks:'No Tutorial and Lab'
{subject_code: HW0110', subject_name: 'Effective Communication', year_of_study: '1', discipline: 'SCE', acad_unit: 2, cohort_size: 150, remarks: 'No Tutorial and Lab'},

Front string: ,('HW110','Effective Communication','2','SCE',2,300,''
Remove 3 char: HW110','Effective Communication','2','SCE',2,300,''
code:HW110'
name:'Effective Communication'
year:'2'
discipline:'SCE'
acad_unit:2
cohort_size:300
remarks:''
{subject_code: HW110', subject_name: 'Effective Communication', year_of_study: '2', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},

Front string: ,('HW210','Technical Communications','2','SCE',2,300,''
Remove 3 char: HW210','Technical Communications','2','SCE',2,300,''
code:HW210'
name:'Technical Communications'
year:'2'
discipline:'SCE'
acad_unit:2
cohort_size:300
remarks:''
{subject_code: HW210', subject_name: 'Technical Communications', year_of_study: '2', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},

Front string: ,('HW310','Professional Communication','3','SCE',2,300,''
Remove 3 char: HW310','Professional Communication','3','SCE',2,300,''
code:HW310'
name:'Professional Communication'
year:'3'
discipline:'SCE'
acad_unit:2
cohort_size:300
remarks:''
{subject_code: HW310', subject_name: 'Professional Communication', year_of_study: '3', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},

Front string: ,('CE8003','HRM & Entrepreneurship','1','CE',3,150,'Shared code with CPE/CSC184'
Remove 3 char: CE8003','HRM & Entrepreneurship','1','CE',3,150,'Shared code with CPE/CSC184'
code:CE8003'
name:'HRM & Entrepreneurship'
year:'1'
discipline:'CE'
acad_unit:3
cohort_size:150
remarks:'Shared code with CPE/CSC184'
{subject_code: CE8003', subject_name: 'HRM & Entrepreneurship', year_of_study: '1', discipline: 'CE', acad_unit: 3, cohort_size: 150, remarks: 'Shared code with CPE/CSC184'},

Front string: ,('CE9002','How Computers Work','1','SCE',4,90,'Same as CM102'
Remove 3 char: CE9002','How Computers Work','1','SCE',4,90,'Same as CM102'
code:CE9002'
name:'How Computers Work'
year:'1'
discipline:'SCE'
acad_unit:4
cohort_size:90
remarks:'Same as CM102'
{subject_code: CE9002', subject_name: 'How Computers Work', year_of_study: '1', discipline: 'SCE', acad_unit: 4, cohort_size: 90, remarks: 'Same as CM102'},

Front string: ,('CE9003','Applying IT','1','SCE',4,90,'Same as CM103'
Remove 3 char: CE9003','Applying IT','1','SCE',4,90,'Same as CM103'
code:CE9003'
name:'Applying IT'
year:'1'
discipline:'SCE'
acad_unit:4
cohort_size:90
remarks:'Same as CM103'
{subject_code: CE9003', subject_name: 'Applying IT', year_of_study: '1', discipline: 'SCE', acad_unit: 4, cohort_size: 90, remarks: 'Same as CM103'},

Front string: ,('HE9091','Principles of Economics','1','SCE',4,300,''
Remove 3 char: HE9091','Principles of Economics','1','SCE',4,300,''
code:HE9091'
name:'Principles of Economics'
year:'1'
discipline:'SCE'
acad_unit:4
cohort_size:300
remarks:''
{subject_code: HE9091', subject_name: 'Principles of Economics', year_of_study: '1', discipline: 'SCE', acad_unit: 4, cohort_size: 300, remarks: ''},

Front string: ,('HW0210','Technical Communications','2','SCE',2,300,''
Remove 3 char: HW0210','Technical Communications','2','SCE',2,300,''
code:HW0210'
name:'Technical Communications'
year:'2'
discipline:'SCE'
acad_unit:2
cohort_size:300
remarks:''
{subject_code: HW0210', subject_name: 'Technical Communications', year_of_study: '2', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},

Front string: ,('HW0310','Professional  Comm','3','SCE',2,300,''
Remove 3 char: HW0310','Professional  Comm','3','SCE',2,300,''
code:HW0310'
name:'Professional  Comm'
year:'3'
discipline:'SCE'
acad_unit:2
cohort_size:300
remarks:''
{subject_code: HW0310', subject_name: 'Professional  Comm', year_of_study: '3', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},

Front string: ,('CE0001','Engineers and Society','1','CE',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183'
Remove 3 char: CE0001','Engineers and Society','1','CE',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183'
code:CE0001'
name:'Engineers and Society'
year:'1'
discipline:'CE'
acad_unit:3
cohort_size:150
remarks:'Shared tutorial - in LT. Shared code with CPE/CSC183'
{subject_code: CE0001', subject_name: 'Engineers and Society', year_of_study: '1', discipline: 'CE', acad_unit: 3, cohort_size: 150, remarks: 'Shared tutorial - in LT. Shared code with CPE/CSC183'},

Front string: ,('CZ0001','Engineers and Societ','1','CSC',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183'
Remove 3 char: CZ0001','Engineers and Societ','1','CSC',3,150,'Shared tutorial - in LT. Shared code with CPE/CSC183'
code:CZ0001'
name:'Engineers and Societ'
year:'1'
discipline:'CSC'
acad_unit:3
cohort_size:150
remarks:'Shared tutorial - in LT. Shared code with CPE/CSC183'
{subject_code: CZ0001', subject_name: 'Engineers and Societ', year_of_study: '1', discipline: 'CSC', acad_unit: 3, cohort_size: 150, remarks: 'Shared tutorial - in LT. Shared code with CPE/CSC183'},

{subject_code: 'HE191', subject_name: 'Principles of Economics', year_of_study: '1', discipline: 'SCE', acad_unit: 3, cohort_size: 300, remarks: 'One 2-hr Lecture'},{subject_code: HW0001', subject_name: 'English Proficiency', year_of_study: '1', discipline: 'SCE', acad_unit: 0, cohort_size: 200, remarks: 'To be conducted by HSS'},{subject_code: HW0110', subject_name: 'Effective Communication', year_of_study: '1', discipline: 'SCE', acad_unit: 2, cohort_size: 150, remarks: 'No Tutorial and Lab'},{subject_code: HW110', subject_name: 'Effective Communication', year_of_study: '2', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},{subject_code: HW210', subject_name: 'Technical Communications', year_of_study: '2', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},{subject_code: HW310', subject_name: 'Professional Communication', year_of_study: '3', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},{subject_code: CE8003', subject_name: 'HRM & Entrepreneurship', year_of_study: '1', discipline: 'CE', acad_unit: 3, cohort_size: 150, remarks: 'Shared code with CPE/CSC184'},{subject_code: CE9002', subject_name: 'How Computers Work', year_of_study: '1', discipline: 'SCE', acad_unit: 4, cohort_size: 90, remarks: 'Same as CM102'},{subject_code: CE9003', subject_name: 'Applying IT', year_of_study: '1', discipline: 'SCE', acad_unit: 4, cohort_size: 90, remarks: 'Same as CM103'},{subject_code: HE9091', subject_name: 'Principles of Economics', year_of_study: '1', discipline: 'SCE', acad_unit: 4, cohort_size: 300, remarks: ''},{subject_code: HW0210', subject_name: 'Technical Communications', year_of_study: '2', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},{subject_code: HW0310', subject_name: 'Professional  Comm', year_of_study: '3', discipline: 'SCE', acad_unit: 2, cohort_size: 300, remarks: ''},{subject_code: CE0001', subject_name: 'Engineers and Society', year_of_study: '1', discipline: 'CE', acad_unit: 3, cohort_size: 150, remarks: 'Shared tutorial - in LT. Shared code with CPE/CSC183'},{subject_code: CZ0001', subject_name: 'Engineers and Societ', year_of_study: '1', discipline: 'CSC', acad_unit: 3, cohort_size: 150, remarks: 'Shared tutorial - in LT. Shared code with CPE/CSC183'},