• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

replace a word

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hwo do i replace the word or by new line ?like if i do it with replaceAll function it replaces or between the words also like in borrow th or is replaced .that is the b is in one line n the row is in the other. so i want to know a function that removes this for me
please do help
thank you
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vaishnavi Mukundhan wrote:hwo do i replace the word or by new line ?like if i do it with replaceAll function...


I don't understand the question.

Perhaps if you provided some examples, and explained exactly what you want to happen and why.

Winston
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first parameter of the replaceAll method is a regular expression, so you need to find a regular expression that matches 'or' with no other letters either side of it. There are plenty of regular expression tutorials on the web if you don't know much about them.
 
vaishnavi Mukundhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stuart A. Burkett wrote:The first parameter of the replaceAll method is a regular expression, so you need to find a regular expression that matches 'or' with no other letters either side of it. There are plenty of regular expression tutorials on the web if you don't know much about them.



it would be really helpful if you can tell me how to represent or in regex? i urgently need it please
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wow... I had to read this five times, before I finally got it....

vaishnavi Mukundhan wrote:hwo do i replace the word or by new line ?like if i do it with replaceAll function it replaces or between the words also like in borrow th or is replaced .that is the b is in one line n the row is in the other. so i want to know a function that removes this for me
please do help
thank you



I think it says ...

how do I replace the word "or" with a "newline" ? If i do it by calling the replaceAll() method, it replaces the "or" between the words too. For example, like in the word "borrow", the "or" sub-word is replaced. that is, the "b" is in one line and the "row" is in the other. I want to know a function that doesn't do this




Anyway...

vaishnavi Mukundhan wrote:

Stuart A. Burkett wrote:The first parameter of the replaceAll method is a regular expression, so you need to find a regular expression that matches 'or' with no other letters either side of it. There are plenty of regular expression tutorials on the web if you don't know much about them.



it would be really helpful if you can tell me how to represent or in regex? i urgently need it please



Regular expressions has the "\b" tag, that is used to specify word boundaries.

Herny
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:I think it says ...


Wow. Fine analysis of SMS-speak; my compliments + cow.

Winston
 
Ranch Hand
Posts: 178
2
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry has explained the question nicely. You have helped me in previous posts too to understand the OP..

There is a way to do it without \b. But \b will be good as it is easy to understand..
 
Marshal
Posts: 79406
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vaishnavi Mukundhan wrote: . . . i urgently need it please

Welcome to the Ranch

Just think how much sooner you would have had answers if anybody could understand your question. And we don’t use words like urgently.
 
vaishnavi Mukundhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

vaishnavi Mukundhan wrote: . . . i urgently need it please

Welcome to the Ranch

Just think how much sooner you would have had answers if anybody could understand your question. And we don’t use words like urgently.


i'll remember that next time
 
vaishnavi Mukundhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vaishnavi Mukundhan wrote:

Stuart A. Burkett wrote:The first parameter of the replaceAll method is a regular expression, so you need to find a regular expression that matches 'or' with no other letters either side of it. There are plenty of regular expression tutorials on the web if you don't know much about them.



it would be really helpful if you can tell me how to represent or in regex? i urgently need it please


it's still not working.

this is my code . Its not giving the desired output.only "." is being replaced .
Please help
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it mean you wish to replace and/AND from every line with a new line character?
 
vaishnavi Mukundhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Does it mean you wish to replace and/AND from every line with a new line character?


yeah.and also ","
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vaishnavi Mukundhan wrote:

vaishnavi Mukundhan wrote:

Stuart A. Burkett wrote:The first parameter of the replaceAll method is a regular expression, so you need to find a regular expression that matches 'or' with no other letters either side of it. There are plenty of regular expression tutorials on the web if you don't know much about them.



it would be really helpful if you can tell me how to represent or in regex? i urgently need it please


it's still not working.

this is my code . Its not giving the desired output.only "." is being replaced .
Please help




This "not working" is different from the previous "not working". In the previous, too many "or"s were being replaced. It this one, it is not getting replaced at all. So, it is safe to assume that this lack of replacement is caused by recent changes.

Henry
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have written unnecessary if clauses in your code. As replaceAll() method need a regex, we can send case insensitive with regex..!

eg:-

No need of if clause at all..

Not this, But I saw a big problem in your if clause..! I think you have to add "\n" to variable data in if block too. If not, you are not moving into a new line. And I think that's why your code is working to "." only..!
 
Campbell Ritchie
Marshal
Posts: 79406
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using the escape sequences in the first place? They are platform‑specific and cannot be relied upon to work correctly. Please check this code carefully before use, in case I have spelt something wrongly.You can use the LINE_END value wherever it is needed, possibly via static import.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vaishnavi Mukundhan wrote:

Swastik Dey wrote:Does it mean you wish to replace and/AND from every line with a new line character?


yeah.and also ","


You know what vaishnavi?

Write down the rules: All of them, and in sequence; because if you don't, you'll be forever wondering if you missed one. And you won't be helping us to help you.

Winston
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic