• Post Reply Bookmark Topic Watch Topic
  • New Topic

replace a word  RSS feed

 
vaishnavi Mukundhan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:I think it says ...

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

Winston
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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..
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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: 56545
172
  • Mark post as helpful
  • send pies
  • 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: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!