Long story short, I have a string of Morse Code, for example ".-- -.. ---" (By the professor's key, which I think is wrong morse code D: anyway it's supposed to say 'Dad'). My best instinct is to go through all the various Morse Code symbols and use Matcher.replaceAll() to replace first all the A's, then all the a's, then all the B's, etc. etc... So here's what I came up with:
for (String symbol : keyList) { String newSymbol = valueList.get(keyList.indexOf(symbol)); // The lists have, of course, the source and target symbols sourceText = Pattern.compile("\b" + symbol + "\b").matcher(sourceText).replaceAll(newSymbol); }
Problem: It doesn't work. The program completes and there are no changes from the source file to the target file. No translation, just the same old morse code string.
Here's what else I've tried:
I tried omitting the \b's. That caused the matcher to ignore the whitespace and just attack every single A it saw right off the bat. So with the above string I got something ridiculous like AB- or something.
I also tried using \\b instead of \b, and supplying 'Pattern.LITERAL' as the second argument. Again, no change. Same for if I only omit one \b or the other.
Suggestions? =/
This post has been edited by squarewavedreams: 13 March 2009 - 07:29 PM