AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String.replaceAll() with regex?

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
wEEdpEckEr
Guest





PostPosted: Tue May 25, 2004 3:17 pm    Post subject: String.replaceAll() with regex? Reply with quote



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
Back to top
Nicholas Pappas
Guest





PostPosted: Thu May 27, 2004 1:54 pm    Post subject: Re: String.replaceAll() with regex? Reply with quote



wEEdpEckEr wrote:
Quote:
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(';', '-');

Back to top
wEEdpEckEr
Guest





PostPosted: Mon May 31, 2004 8:16 am    Post subject: Re: String.replaceAll() with regex? Reply with quote



Nicholas Pappas <noreply (AT) rightstep (DOT) org> schreef op do, 27 mei 2004
13:54:18 GMT in news:c94rmi$hcr$2 (AT) charm (DOT) magnus.acs.ohio-state.edu:

Quote:
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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.