Currently I am replacing just a character with something different, as it is a music sheet that needs to be altered the character might differ. Therefore I created a JavaScript code which will replace all these letters if on the sheet.
Here the problem occurs, If I have character A which needs to be replaced with C and later on in the same JavaScript code C needs to be replaced with D. Therefore A changes to D instead of C. I need every character replaced once per action instead of comparing the replaced text with other possibilities.
Here is my code so far:
function Dkoord() {
$('[id^=harm] > text:nth-child(1) > tspan:nth-child(1)').text(function(i, text) {
return text.replace('A', 'B').replace('A#', 'C').replace('Bb', 'C')
.replace('B', 'C#').replace('C', 'D').replace('C#', 'D#')
.replace('Db', 'Eb').replace('D', 'E').replace('D#', 'F')
.replace('Eb', 'F').replace('F', 'G').replace('F#', 'G#')
.replace('Gb', 'Ab').replace('G', 'A').replace('G#', 'A#')
.replace('Ab', 'Bb');
});
}
As you can see C is changing to D but later on changing the D to E, I just want a character to be compared once. How do I do this.