• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

String replacer

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to replace a string by another string in text paragraph. Is anymethod already available to do this? I am using jdk1.2.2/jdk1.3. Thanks
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<reply>
u can us setText(String s);
to set the text of the TextaArea or TextField , whtever is the
class of Text paragraph u talked offf...
</reply>
Cheers :-)-
s a h i l
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roi,
Unfortunately, there is no method that does this directly, in the Java APIs.
If you need to replace a "word" by another word in a any text string, one way is to use a StringTokenizer to take out all words (token) from your string, one at a time. Then build back that string from scratch, replacing the searched word by its replacement word.
You can have sample code at:
http://www.javaranch.com/ubb/Forum33/HTML/000518.html
You run the SNR.java with a text file name, the searched word, and the replacement word, and it does the job without confusion.
For example, say the text:
I read one book this week. Book? Rather a good book! I found it at the bookstore. How many books(did you write?)...
Then replace the word book with newspaper, you'll get the resulting text:
I read one newspaper this week. Book? Rather a good newspaper! I found it at the bookstore. How many books(did you write?)...
Notice that the resulting text kept "Book", "bookstore", and "books". This is strict word replacement. But you could change the program slightly.
Goodbye
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic