Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Replacing char in String with Ints.
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Krocker




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: 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?
Krocker




PostPosted: 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.
Krocker




PostPosted: 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 Sad
DemonWasp




PostPosted: 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.
Krocker




PostPosted: 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?
DemonWasp




PostPosted: 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?
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: