Computer Science Canada Replacing char in String with Ints. |
Author: | Krocker [ Thu Oct 03, 2013 8:35 pm ] |
Post subject: | Replacing char in String with Ints. |
So i need to write a program that takes in a string from the user. Then print out the string with all of the vowels replaced with their leet-speak equivalents ? A = 4, E = 3, I = 1, O = 0, for U use a *. However, i have nooooo idea how to do this, at all!!!! Please help me. |
Author: | DemonWasp [ Thu Oct 03, 2013 8:46 pm ] |
Post subject: | RE:Replacing char in String with Ints. |
Look at the functions String provides. I'll assume you're using Ready to Program for Java, here's the link for Java 1.4.2: http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html Which of those functions does what you want? |
Author: | Krocker [ Thu Oct 03, 2013 9:00 pm ] |
Post subject: | Re: Replacing char in String with Ints. |
So i used the replace and the replaceAll functions, but nothing happens to the string. String leetSpeak = inputString.replaceAll ("a", "4"); String leetSpeak = inputString.replace ("i", "1"); I have tried with different inputs, but nothing changes. |
Author: | Krocker [ Thu Oct 03, 2013 9:05 pm ] |
Post subject: | RE:Replacing char in String with Ints. |
Nvm, i figure wat was wrong, i was using the wrong variables to store the multiple strings. Also, im not using RTP, im using Notepad++. Anyways, i have another question, how would i remove all Uppercase letters from the string? i didnt see any function for that ![]() |
Author: | DemonWasp [ Thu Oct 03, 2013 9:26 pm ] |
Post subject: | RE:Replacing char in String with Ints. |
Remove all upper-case letters? That's best done through replaceAll (which takes a regular expression, by the way). If you meant "convert upper-case letters to lower case", then there's a toLowerCase() function that does that. String in Java are [i]immutable[i], which means that methods which would change the string (like substring, replace, etc) will return a different String while leaving the original String unchanged. |
Author: | Krocker [ Thu Oct 03, 2013 9:33 pm ] |
Post subject: | RE:Replacing char in String with Ints. |
if i use replace all, i would have to do a for, and check for each capital letter and replace it with a space, then trim the space out. isnt there a faster, more efficient way? |
Author: | DemonWasp [ Fri Oct 04, 2013 7:26 am ] |
Post subject: | RE:Replacing char in String with Ints. |
There is!. Read the exact documentation for String.replaceAll() very carefully. Does it provide a way to say "all capital letters"? Are there any words you don't recognize? What does Google have to say about those words? |