PC Review


Reply
Thread Tools Rate Thread

Add value in string

 
 
shapper
Guest
Posts: n/a
 
      7th May 2009
Hello,

I have a String as follows:

<p class="Error">Some text</p>

I need to wrap the inner text "Some text" in a span tag like:

<p class="Error"><span>Some text</span></p>

I can't make a direct replace because the paragraph class can be:
<p>, <p class="SomeClass">, <p class="SomeClass" id="MyP">, ...

Any idea how to make this?

I was thinking in Regex but I don't know how and I am not even sure if
it is the best option.

Thanks,
Miguel
 
Reply With Quote
 
 
 
 
Jesse Houwing
Guest
Posts: n/a
 
      7th May 2009
Hello shapper,

> Hello,
>
> I have a String as follows:
>
> <p class="Error">Some text</p>
>
> I need to wrap the inner text "Some text" in a span tag like:
>
> <p class="Error"><span>Some text</span></p>
>
> I can't make a direct replace because the paragraph class can be: <p>,
> <p class="SomeClass">, <p class="SomeClass" id="MyP">, ...
>
> Any idea how to make this?
>
> I was thinking in Regex but I don't know how and I am not even sure if
> it is the best option.



have a look at the HTML Agility Pack, I think that willallow you to use an
XSL Transfor to add the values you're looking for. Alternatively, this can
be done with a Regex, but you'd need to provide a little more info on the
possible examples where you DO and where you DON'T want to replace...

something like (<P[^>]*>)((??!</P).)*)

and replace that with

$1<span>$2</span>

should get you going... But mind you that there are a lot of conditions that
might not work with such a simple regex. And that it migth be impossible
to think up one that will work under all conditions. My advice is, if it's
for a one off conversion, use it. If you want to use it regularly (like in
a production environment) don't.

--
Jesse Houwing
jesse.houwing at sogeti.nl


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string? Daniel Microsoft Dot NET 7 12th Nov 2004 09:08 AM
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string? Daniel Microsoft C# .NET 10 3rd Nov 2004 03:26 PM
Cannot create an object of type 'System.String[]' from its string representation 'String[] Array' for the 'Options' property. Hessam Microsoft C# .NET 0 8th Aug 2003 09:45 AM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Mikael Jansson Microsoft C# .NET 0 31st Jul 2003 08:42 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Frank Oquendo Microsoft C# .NET 0 31st Jul 2003 08:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 AM.