Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

String.replaceAll() with regex?

Thread view: 
wEEdpEckEr - 25 May 2004 16:17 GMT
Hi,

I have an xml file with a few attributes, e.g. <draw:image draw:style-
name="id4" ... >

Now, what I would like to do is replace all semi-colons with hyphens ("-").
For the tag-name itself this isn't really a problem, since I can check
wheater a "<" preceeds the tag, but for the attributes it is, since not all
attributes appear always, nor in the same order. I tried something like
this:
XML = XML.replaceAll("<[^>]*draw:style-name=\"","<[^>]*draw-style-name=
\"");

but in the result, the "[^>]*" string is being added, instead of the
preceeding text that was there before. Is there a way to make sure the rest
of the text stays in place?

TIA
Nicholas Pappas - 27 May 2004 14:54 GMT
> Now, what I would like to do is replace all semi-colons with hyphens ("-").

    The String class has a replace function which should do what you want.
   
    String xmlString = "<draw:image draw ... >"
    String xmlCleaned;
    xmlCleaned = xmlString.replace(';', '-');
wEEdpEckEr - 31 May 2004 09:16 GMT
>      The String class has a replace function which should do what you
>      want.
>      
>      String xmlString = "<draw:image draw ... >"
>      String xmlCleaned;
>      xmlCleaned = xmlString.replace(';', '-');

euh, yeah, well, that's a little too simple, you see. In between the tags
can be regular text, e.g.
"<text:p>Some text: and other text</text:p>"

and I don't want the text to be changed. That's why I have to check if
there are "<" and ">" before and after the colon (not semi-colon, sorry,
confusing names for none English speaking persons).

greetz
Tim


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.