fork download
  1. import java.util.*;
  2. class ChangeTextProgram {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. 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')";
  7. /*,('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')
  8.  ('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')*/
  9. String lastString = "";
  10. String semiFinal="";
  11. Scanner input = new Scanner(str);
  12.  
  13. String delistr = "\\)";
  14. input.useDelimiter(delistr);
  15.  
  16. while(input.hasNext()){
  17. String frontstring=input.next();
  18. System.out.println("Front string: " + frontstring );
  19. String afterRemove3Char = frontstring.substring(3);
  20. System.out.println("Remove 3 char: " + afterRemove3Char);
  21.  
  22. Scanner data = new Scanner(afterRemove3Char);
  23. data.useDelimiter(",");
  24.  
  25. while(data.hasNext()){
  26. String code = data.next();
  27. System.out.println("code:" +code);
  28.  
  29. String name = data.next();
  30. System.out.println("name:" +name);
  31.  
  32. String year = data.next();
  33. System.out.println("year:" +year);
  34.  
  35. String discipline = data.next();
  36. System.out.println("discipline:" +discipline);
  37.  
  38. String acad_unit = data.next();
  39. System.out.println("acad_unit:" +acad_unit);
  40.  
  41. String cohort_size = data.next();
  42. System.out.println("cohort_size:" +cohort_size);
  43.  
  44. String remarks = data.next();
  45. System.out.println("remarks:" +remarks);
  46.  
  47. /* attr_accessible :acad_unit, /
  48.   :cohort_size, /
  49.   :discipline, /
  50.   :remarks, /
  51.   :subject_code, /
  52.   :subject_name, /
  53.   :year_of_study, /
  54.   :lessons_attributes #foreign*/
  55.  
  56. /* {venue_name: 'C&I', venue_type: 'Lab', capacity: 80, remarks: 'Control and Instrumentation'},
  57.   {subject_code: code, subject_name: name, year_of_study: year, discipline: discipline, acad_unit:acad_unit, cohort_size: cohort_size, remarks: remarks}, */
  58.  
  59. semiFinal = "{subject_code: " +code + ", subject_name: " +name + ", year_of_study: " +year + ", discipline: " +discipline + ", acad_unit: " +acad_unit + ", cohort_size: " +cohort_size + ", remarks: " + remarks + "},";
  60. System.out.println(semiFinal);
  61. }
  62.  
  63. lastString = lastString + semiFinal;
  64.  
  65. System.out.println();
  66.  
  67. }
  68.  
  69. System.out.println(lastString);
  70.  
  71. }
  72.  
  73. }
Success #stdin #stdout 0.23s 61660KB
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'},