In the code below, I'm trying to convert a sentence into shorthand, meaning I take away all the vowels, plus I convert "and" to "&", "to" to "2", "you" to "U", and "for" to "4".
public static String shorthandString (String shstr)
{
String shortHandString = "";
shortHandString = Pattern.compile ("and").matcher (shortHandStrin g).replaceAll(" &");
shortHandString = shortHandString .replaceAll("to ", "2");
shortHandString = shortHandString .replaceAll("yo u", "U");
shortHandString = shortHandString .replaceAll("fo r", "4");
//Check string and replace vowel.
for (int n = 0; n < shstr.length(); n++)
{
if (!checkVowel(sh str.charAt(n)) && (shstr.charAt(n ) != 'U'))
{
shortHandString += shstr.charAt(n) ;
}
}
return shortHandString ;
}
I'm having trouble with the replace all because, for example, if i input "and", it returns "nd" not "&".
public static String shorthandString (String shstr)
{
String shortHandString = "";
shortHandString = Pattern.compile ("and").matcher (shortHandStrin g).replaceAll(" &");
shortHandString = shortHandString .replaceAll("to ", "2");
shortHandString = shortHandString .replaceAll("yo u", "U");
shortHandString = shortHandString .replaceAll("fo r", "4");
//Check string and replace vowel.
for (int n = 0; n < shstr.length(); n++)
{
if (!checkVowel(sh str.charAt(n)) && (shstr.charAt(n ) != 'U'))
{
shortHandString += shstr.charAt(n) ;
}
}
return shortHandString ;
}
I'm having trouble with the replace all because, for example, if i input "and", it returns "nd" not "&".
Comment