- Joined
- Oct 24, 2013
- Messages
- 47
- Reaction score
- 0
Please not the values inside the string are all dynamic.
JavaScript:
let abc = '[{"userid":"88623619","organisations":"Imperial College London*Imperial College Healthcare NHS Trust*Imperial College Healthcare NHS Trust*Imperial College Healthcare NHS Trust*Milton Keynes Hospital NHS Foundation Trust*","oversightGroupRole":"Chair","oversightGroupMemberName":"Dr Ahmed Ahmed","oversightGroupType":"Steering Committee"},{"userid":"88624025","organisations":"Bangor University*Barnet, Enfield and Haringey Mental Health NHS Trust*Cambridge University Hospitals NHS Foundation Trust*","oversightGroupRole":"Public Member","oversightGroupMemberName":"Professor b b","oversightGroupType":"Advisory Group"},{"userid":"88623985","organisations":"Aberdeen And District Fibromyalgia Support Group*Additive Design Ltd*Altnagelvin Area Hospital*Ataxia UK*Tameside Hospital NHS Foundation Trust*","oversightGroupRole":"Chair","oversightGroupMemberName":"Chief TestTestRr TestTestRr","oversightGroupType":"Data Monitoring Committee"},]';
//the Desried Result is
//abc = '[{"userid":"88623619","organisations":"Imperial College London*Imperial College Healthcare NHS Trust*Imperial College Healthcare NHS Trust*Imperial College Healthcare NHS Trust*Milton Keynes Hospital NHS Foundation Trust","oversightGroupRole":"Chair","oversightGroupMemberName":"Dr Ahmed Ahmed","oversightGroupType":"Steering Committee"},{"userid":"88624025","organisations":"Bangor University*Barnet, Enfield and Haringey Mental Health NHS Trust*Cambridge University Hospitals NHS Foundation Trust","oversightGroupRole":"Public Member","oversightGroupMemberName":"Professor b b","oversightGroupType":"Advisory Group"},{"userid":"88623985","organisations":"Aberdeen And District Fibromyalgia Support Group*Additive Design Ltd*Altnagelvin Area Hospital*Ataxia UK*Tameside Hospital NHS Foundation Trust","oversightGroupRole":"Chair","oversightGroupMemberName":"Chief TestTestRr TestTestRr","oversightGroupType":"Data Monitoring Committee"},]';
My Code which is not working:
let abc = '[{"userid":"88623619","organisations":"Imperial College London*Imperial College Healthcare NHS Trust*Imperial College Healthcare NHS Trust*Imperial College Healthcare NHS Trust*Milton Keynes Hospital NHS Foundation Trust*","oversightGroupRole":"Chair","oversightGroupMemberName":"Dr Ahmed Ahmed","oversightGroupType":"Steering Committee"},{"userid":"88624025","organisations":"Bangor University*Barnet, Enfield and Haringey Mental Health NHS Trust*Cambridge University Hospitals NHS Foundation Trust*","oversightGroupRole":"Public Member","oversightGroupMemberName":"Professor b b","oversightGroupType":"Advisory Group"},{"userid":"88623985","organisations":"Aberdeen And District Fibromyalgia Support Group*Additive Design Ltd*Altnagelvin Area Hospital*Ataxia UK*Tameside Hospital NHS Foundation Trust*","oversightGroupRole":"Chair","oversightGroupMemberName":"Chief TestTestRr TestTestRr","oversightGroupType":"Data Monitoring Committee"},]';
abc = abc.replace(/,(?=[^,]*$)/, '');
let startIndex = 0;
while ((startIndex = abc.indexOf('"organisations":', startIndex)) !== -1) {
let endIndex = abc.indexOf('*', startIndex + '"organisations":'.length);
if (endIndex !== -1) {
abc = abc.slice(0, endIndex) + abc.slice(endIndex + 1);
}
startIndex += '"organisations":'.length;
}
console.log(abc);
Last edited: