Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-16-2007, 05:02 PM
Member
 
Join Date: Jul 2007
Posts: 26
paul is on a distinguished road
Using a replace method...
Hi, I am writing a java code and I need help with replacing the word I am starting off with into asterisks without using a while method.

So for example:

enter a word -> hello

**
So how can I go from "hello" to "**" using a replace method? Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-16-2007, 05:09 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Please explain more clearly. I did not understand what you want to do..
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-07-2007, 05:50 AM
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
I don't quite understand your question, but I'll give some advice.

Code:
String word = hello; for(int i = 0; i < word.length; i++) { word.replace(word[i], "*"); }
If my code above is syntactically correct, that will replace all letters in "word" with *. But since you've changed "hello" to "*****" you've lost the secret word completely. Maybe you want something like...

Code:
String word = hello; String coverUpWord = ''; for(int i = 0; i < word.length; i++) { coverUpWord += '*'; }
Now both the above use for-loops not while-loops, but they are essentially the same. Why is it that you can't use a while-loop?

Greetings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace ( in a String hamish10101 New To Java 6 01-17-2008 06:51 AM
Find and Replace in JTable look4 AWT / Swing 2 11-24-2007 01:27 AM
problems with replace method cecily New To Java 1 08-02-2007 10:11 PM
String replace method venkata.tarigopula Advanced Java 1 07-10-2007 09:14 PM
Using Find And Replace In Eclipse IDE JavaForums Eclipse 0 04-26-2007 11:15 AM


All times are GMT +3. The time now is 09:36 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org