Hi, i would like to know how to replace every char in a string with a
certin given char using the String.replace(char oldChar,char newChar).
I would like to replace all letters with an underscore ie. "hello
world" will be come...
"_ _ _ _ _ _ _ _ _ _" (ive added xtra spaces so it dosnt look like
one line!) with the method i have written only the last char is
replaced, loop problem i guess!
public String hideWord(String word)
{
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String hiddenWord="";
for(int i = 0;i<word.length();i++)
{
char temp = word.charAt(i);
for(int j=0;j<alphabet.length();j++)
{
char letters = alphabet.charAt(j);
if(temp == letters)
{
hiddenWord = word.replace(temp,'_');
}
}
}
return hiddenWord;
}
Any help much appreciated! Thanks :)