• Post Reply Bookmark Topic Watch Topic
  • New Topic

String replace  RSS feed

 
luca williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I'm trying to figure out how i can find a value in a textPane and replace it with another value.

Eg:


I'm trying to find "modelid=" and replace it with "objectid=" but where the {} are it can be any number so if i enter modelid=42 it will convert to objectid=42.

Thanks
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you expect "modelid=" to sometimes be followed by a non-digit ?
 
luca williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Do you expect "modelid=" to sometimes be followed by a non-digit ?

modelid is only a int, so if i search modelid="3432" it will replace it with objectid="3432"
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me that replacing "modelid=" by "objectid=" would be sufficient, since that's your stated requirement. I don't see why you need to mess about with whatever follows that, because you aren't going to change that part anyway. Or am I missing something?
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

The String to replace is a regular expression so the {} means something different from what you think it does. Go through the Java™ Tutorials section and see what it says about how many instances of the regex you have. That might be what the {} mean.
Paul C is right: why not simply use "modelid="
Unless there is something else we don't know about.
 
luca williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your replays.

I have been doing some research in the meantime and found that i might have explained my question a bit wrong.

this is the input i want to convert:



into:



I found that if i use a reformatting expression i might be able to convert it. im also not sure how it would work with multiple lines.

Thanks
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a full XML file, I would look into using a SAX Parser.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!