By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,786 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,786 IT Pros & Developers. It's quick & easy.

Replacing span tags

P: n/a
Hi There...

I'm struggling with a problem:
I have a string (coming from a rich text editor) which contains a variety of
span tags that need to be replaced with corresponding formatting tags.
e.g.

<span style="font-weight: bold;">line 2</span>

needs to become
<b>line 2</b>

So... with a single set of tags its simple. But then when you add in the
underline and italic <span> tags it becomes a right mess - especially if you
get nested tags which means you can't just replace the next </span> tag with
the relevant formatting closing tag as it could be the closing tag from
another nested tag.

e.g.

<span style="font-weight: bold;">bold and <span style="font-style:
italic;">italic <span style="text-decoration: underline;">Underlined bold &
italic!! </span> just italic</span> now bold again </span>not bold<br />

Can anyone help?

Cheers

David Henderson
Jul 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Hi David,

Confused as to why this needs to be done, whats wrong with span tags?
But, you would need to write your own function to acheive the desired
results.

Read up on searching with regular expressions, and the replace() function.

Tom
Jul 19 '05 #2

P: n/a
"Thomas Gullen" wrote in message news:41**************@drum-world.com...
: Confused as to why this needs to be done, whats wrong with span tags?
: But, you would need to write your own function to acheive the desired
: results.
:
: Read up on searching with regular expressions, and the replace() function.

....and how is this asp related?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #3

P: n/a
What, are you the off-topic OD today?

I would venture to say the question and answer given are more ASP-related
than *your* answer. How was that ASP-related?

Bob Lehmann

"Roland Hall" <nobody@nowhere> wrote in message
news:ez**************@TK2MSFTNGP10.phx.gbl...
"Thomas Gullen" wrote in message news:41**************@drum-world.com...
: Confused as to why this needs to be done, whats wrong with span tags?
: But, you would need to write your own function to acheive the desired
: results.
:
: Read up on searching with regular expressions, and the replace() function.
...and how is this asp related?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp

Jul 19 '05 #4

P: n/a
> ...and how is this asp related?

I'd attempted an asp solution and was looking for any ideas relating to
one... so seems fairly related to me ;-)

David Henderson
Jul 19 '05 #5

P: n/a
"Thomas Gullen" <ad***@drum-world.com> wrote in message
news:41**************@drum-world.com...
Hi David,

Confused as to why this needs to be done, whats wrong with span tags?
But, you would need to write your own function to acheive the desired
results.

Read up on searching with regular expressions, and the replace() function.

Tom


In addition to Tom's suggestion, you may also want to consider XSLT if the
data is well formed(i.e. valid XML). As you've already alluded to, regular
expressions are linear in nature and as such are not well suited to nested
structures.
Jul 19 '05 #6

P: n/a
"Bob Lehmann" wrote in message news:eD**************@TK2MSFTNGP15.phx.gbl...
: What, are you the off-topic OD today?

Bob...

Show me the ASP related code in this post.

: I would venture to say the question and answer given are more ASP-related
: than *your* answer. How was that ASP-related?

You're just too quick Bob however, I didn't provide an answer. I only asked
a question. Your response is of no use. But, to answer your ridiculous
question, I'll provide a ridiculous answer. My question at least had the
word ASP included. Happy now?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #7

P: n/a
"David Henderson" wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
:> ...and how is this asp related?
:
: I'd attempted an asp solution and was looking for any ideas relating to
: one... so seems fairly related to me ;-)

Sorry Dave...

I don't see anything related to ASP other than it's in this NG. You have
only provided client-side code AFAICT. I only see inline styles with DOM
related HTML.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #8

P: n/a
: I'd attempted an asp solution and was looking for any ideas relating to
: one... so seems fairly related to me ;-)

Sorry Dave...

I don't see anything related to ASP other than it's in this NG. You have
only provided client-side code AFAICT. I only see inline styles with DOM
related HTML.


Its OK Roland... I'll forgive you for not being a mind reader!
I was originally going to post my attempt(s) but
a) they didnt come close to working
b) they were badly put together
c) they were huge

So I decided for the sanity of everyone else not to. I was really just
looking for some pointers towarrds a method... but I've sorted it out now
anyway!

Sorry to be a pain in the ass!

David Henderson
Jul 19 '05 #9

P: n/a
"David Henderson" wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
:
: > : I'd attempted an asp solution and was looking for any ideas relating
to
: > : one... so seems fairly related to me ;-)
: >
: > Sorry Dave...
: >
: > I don't see anything related to ASP other than it's in this NG. You
have
: > only provided client-side code AFAICT. I only see inline styles with
DOM
: > related HTML.
: >
:
: Its OK Roland... I'll forgive you for not being a mind reader!
: I was originally going to post my attempt(s) but
: a) they didnt come close to working
: b) they were badly put together
: c) they were huge
:
: So I decided for the sanity of everyone else not to. I was really just
: looking for some pointers towarrds a method... but I've sorted it out now
: anyway!
:
: Sorry to be a pain in the ass!

Dave...

Clarification via a discussion does not make one a pain in the ass. If your
code worked you wouldn't be asking for advice. You should probably never
post all of your code but rather relevant code regarding your issue. If
someone needs more info to help, they'll usually ask. I come here to gain
knowledge and help where I can. Sometimes I'm successful. In this case, I
needed more information because you're right, I'm not a mind reader but I
play one on TV.

Glad you got a handle on your issue and thanks for responding.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.