Replace a word within a string without using replace function


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Replace a word within a string without using replace function

  1. #1
    Join Date
    Oct 2005
    Posts
    1

    Exclamation Replace a word within a string without using replace function

    Hi,

    How can i take a string lets say "sentence" and a word wordOne and an other word wordTwo. And replace within sentence wordOne by wordTwo without using the function

    Code:
    sentence.replace(wordOne, wordTwo);
    Is it possible to maybe chop off the string into diffewrent part match the word and swap it then reconstruct the string and display.

    Thanks
    JD

  2. #2
    Join Date
    Aug 2005
    Posts
    43
    Quote Originally Posted by jingsee
    Hi,
    Is it possible to maybe chop off the string into diffewrent part match the word and swap it then reconstruct the string and display.

    Thanks
    JD
    Check out the subString StringTokenizer class to divide the sentence into a set of words, then you can just iterate through them to see which ones you're looking for and create a new String object with the final (switched) result:

    StringTokenizer: http://java.sun.com/j2se/1.5.0/docs/...Tokenizer.html

Similar Threads

  1. Replies: 8
    Last Post: 03-08-2003, 07:25 PM
  2. verify local admin
    By Patrick Comeau in forum VB Classic
    Replies: 6
    Last Post: 03-22-2001, 11:50 PM
  3. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 0
    Last Post: 08-10-2000, 10:16 PM
  4. Please help me -- urgent -- deadlock error
    By chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 08:36 AM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 04:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center