• Post Reply Bookmark Topic Watch Topic
  • New Topic

text processing  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to make a text processing and using function like Regular expression found in java script for example if i have a line like this
<img align="left" src="/img/i.gif">
or
<IMG align="left" src="/img/i.gif">
or
<IMG src="/img/i.gif" align="left">
i need to convert it to
<img align="left" src="http://localhost/img/i.gif">
so it should be not case sensetive . i can do that with javascript Regular expression but i don't know how to do that with java
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
There are 2 ways to perform the text processing out here one is you use this package called
com.stevesoft.pat at http://www.javaregex.com/ install it in ur jdk and then you can use the regex
or the second thin tht you can do is
use the lastIndexof() function to find the last index of "= "and ">"and extract everytin between them using substring that will give u your url then concatenate whtever u want to it and regenerate the entire <img> tag again.
Hope this helps.Let me know if it was of any help.Cya
 
Usama Rashwan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i deciede to use ParserDelegator to parse the html file and change the value of the attribute that i need to change and i manged to do that but i don't know how to write the new values to a new html file
here is example of what i do
HTMLEditorKit.ParserCallback callback =
new HTMLEditorKit.ParserCallback () {
public void handleText(char[] data, int pos) {
System.out.println(data);
}
};
Reader reader = new FileReader("myFile.html");
new ParserDelegator().parse(reader, callback, false);
i need to write the new html to file
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!