So I'm trying to write a program that takes a String (str) and converts it to NATO Phonetic Alphabet (newSentence).
This is what I tried:
newSentence = str.toLowerCase().replace("a", "Alpha ")
.replace("b", "Bravo ")
.replace("c", "Charlie ")
.replace("d", "Delta ")
.replace("e", "Echo ")
.replace("f", "Foxtrot ")
.replace("g", "Golf ")
.replace("h", "Hotel ")
.replace("i", "India ")
.replace("j", "Juliet ")
.replace("k", "Kilo ")
.replace("l", "Lima ")
.replace("m", "Mike ")
.replace("n", "November ")
.replace("o", "Oscar ")
.replace("p", "Papa ")
.replace("q", "Quebec ")
.replace("r", "Romeo ")
.replace("s", "Sierra ")
.replace("t", "Tango ")
.replace("u", "Uniform ")
.replace("v", "Victor ")
.replace("w", "Whiskey ")
.replace("x", "X-Ray ")
.replace("y", "Yankee ")
.replace("z", "Zulu ");
However, this obviously doesn't work since after it replaces every "a" with "Alpha," it'll take every "l" "p" and "h" and reconvert those and so on. Is there some way to convert all of the letters at once so that this doesn't happen, and make it much more efficient?