I am trying to come up with theString.Format expression to format a number that will have a comma to separate the thousands and a period for the decimals ( I want to show only two decimals )
Will this work for you?
String.Format("{0:N2}", MyNumber)
I am trying to come up with theString.Format expression to format a number that will have a comma to separate the thousands and a period for the decimals ( I want to show only two decimals )
Will this work for you?
String.Format("{0:N2}", MyNumber)
I'm looking for help with a regular expression and c#.
I want to remove all tags from a piece of html except the following.
<a>
<b>
<h1>
<h2>
<h3
Also, <a> could be <a href="http://links.10026.com/?link=aa">aaa</a> etc.
Help would be appreciated, along with an explanation of the reg
expression created.
Thanks.HTML is complex. It would be better instead to say that you want to
*retrieve* *only* all of the following tags. That way, they are the only
tags the Regular Expression will have to look for.
The following will do this:
(?i)<\s*(a|br|h1|h2|h3)[^>]*>(?:([^<\r\n]+)(?=(?:<\/\1)|(?:\r?\n)))?
Note: Grouping is used in this Regular Expression. It groups the tag names
into Group 1, and the InnerText into Group 2, in case you need either of
these.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.
"Spondishy" <spondishy@.tiscali.co.uk> wrote in message
news:1141639561.492632.61150@.z34g2000cwc.googlegro ups.com...
> Hi,
> I'm looking for help with a regular expression and c#.
> I want to remove all tags from a piece of html except the following.
> <a>
> <b>
> <h1>
> <h2>
> <h3>
> Also, <a> could be <a href="http://links.10026.com/?link=aa">aaa</a> etc.
> Help would be appreciated, along with an explanation of the reg
> expression created.
> Thanks.
i use this in VB
Private Function stripHTML(ByVal strHTML) As String
Dim objRegExp As New System.Text.RegularExpressions.Regex("<(.|\n)+?>")
Return objRegExp.Replace(strHTML, "")
End Function
so the regex System.Text.RegularExpressions.Regex("<(.|\n)+?>")
does the trick
so in C# it would be ( i am a VB coder so don`t shoot me )
private string stripHTML(object strHTML)
{
System.Text.RegularExpressions.Regex objRegExp = new
System.Text.RegularExpressions.Regex("<(.|\n)+?>");
return objRegExp.Replace(strHTML, "");
}
regards
Michel Posseth [MCP]
"Spondishy" <spondishy@.tiscali.co.uk> wrote in message
news:1141639561.492632.61150@.z34g2000cwc.googlegro ups.com...
> Hi,
> I'm looking for help with a regular expression and c#.
> I want to remove all tags from a piece of html except the following.
> <a>
> <b>
> <h1>
> <h2>
> <h3>
> Also, <a> could be <a href="http://links.10026.com/?link=aa">aaa</a> etc.
> Help would be appreciated, along with an explanation of the reg
> expression created.
> Thanks.
The problem with that Regular Expression (in this case) is that it simply
matches all tags in the page. It doesn't match InnerText, as he requested,
and it matches end tags as separate matches. It is excellent for, for
example, stripping HTML tags from a page, but not for his requirements.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.
"m.posseth" <michelp@.nohausystems.nl> wrote in message
news:%23kpfPDSQGHA.5092@.TK2MSFTNGP11.phx.gbl...
>
> i use this in VB
> Private Function stripHTML(ByVal strHTML) As String
> Dim objRegExp As New System.Text.RegularExpressions.Regex("<(.|\n)+?>")
> Return objRegExp.Replace(strHTML, "")
> End Function
> so the regex System.Text.RegularExpressions.Regex("<(.|\n)+?>")
> does the trick
> so in C# it would be ( i am a VB coder so don`t shoot me )
> private string stripHTML(object strHTML)
> {
> System.Text.RegularExpressions.Regex objRegExp = new
> System.Text.RegularExpressions.Regex("<(.|\n)+?>");
> return objRegExp.Replace(strHTML, "");
> }
> regards
> Michel Posseth [MCP]
>
>
> "Spondishy" <spondishy@.tiscali.co.uk> wrote in message
> news:1141639561.492632.61150@.z34g2000cwc.googlegro ups.com...
>> Hi,
>>
>> I'm looking for help with a regular expression and c#.
>>
>> I want to remove all tags from a piece of html except the following.
>>
>> <a>
>> <b>
>> <h1>
>> <h2>
>> <h3>
>>
>> Also, <a> could be <a href="http://links.10026.com/?link=aa">aaa</a> etc.
>>
>> Help would be appreciated, along with an explanation of the reg
>> expression created.
>>
>> Thanks.
>>
Oops :-)
i just read "Stripping html tags from text" and missed the exclusion part
>>>except the following.
>>>
>>> <a>
>>> <b>
>>> <h1>
>>> <h2>
>>> <h3>
>>>
>>> Also, <a> could be <a href="http://links.10026.com/?link=aa">aaa</a> etc.
my code will convert
<html>
<head>
<body>
<table>
<tr><td>bla bla </td></tr>
</table>
</body>
</head>
</html
into
bla bla
regards
Michel
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:eISasoSQGHA.4900@.TK2MSFTNGP09.phx.gbl...
> The problem with that Regular Expression (in this case) is that it simply
> matches all tags in the page. It doesn't match InnerText, as he requested,
> and it matches end tags as separate matches. It is excellent for, for
> example, stripping HTML tags from a page, but not for his requirements.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Presuming that God is "only an idea" -
> Ideas exist.
> Therefore, God exists.
> "m.posseth" <michelp@.nohausystems.nl> wrote in message
> news:%23kpfPDSQGHA.5092@.TK2MSFTNGP11.phx.gbl...
>>
>>
>> i use this in VB
>>
>> Private Function stripHTML(ByVal strHTML) As String
>>
>> Dim objRegExp As New System.Text.RegularExpressions.Regex("<(.|\n)+?>")
>>
>> Return objRegExp.Replace(strHTML, "")
>>
>> End Function
>>
>> so the regex System.Text.RegularExpressions.Regex("<(.|\n)+?>")
>>
>> does the trick
>>
>> so in C# it would be ( i am a VB coder so don`t shoot me )
>>
>> private string stripHTML(object strHTML)
>>
>> {
>>
>> System.Text.RegularExpressions.Regex objRegExp = new
>> System.Text.RegularExpressions.Regex("<(.|\n)+?>");
>>
>> return objRegExp.Replace(strHTML, "");
>>
>> }
>>
>> regards
>>
>> Michel Posseth [MCP]
>>
>>
>>
>>
>>
>> "Spondishy" <spondishy@.tiscali.co.uk> wrote in message
>> news:1141639561.492632.61150@.z34g2000cwc.googlegro ups.com...
>>> Hi,
>>>
>>> I'm looking for help with a regular expression and c#.
>>>
>>> I want to remove all tags from a piece of html except the following.
>>>
>>> <a>
>>> <b>
>>> <h1>
>>> <h2>
>>> <h3>
>>>
>>> Also, <a> could be <a href="http://links.10026.com/?link=aa">aaa</a> etc.
>>>
>>> Help would be appreciated, along with an explanation of the reg
>>> expression created.
>>>
>>> Thanks.
>>>
>>
>>
I have the following rule in my web.config that is used in a url redirect
<RewriterRule>
___<LookFor>~/Category/(\w+)\.aspx></LookFor>
___<SendTo><![CDATA[~/Page.aspx?m=13&i=$1]]></SendTo>
</RewriterRule>
This works fine. I'm trying to do a slightly more complex one but I'm having problems with the correct expression and was hoping someone could help.
I'm trying to set it up so it when you browse to /Category/Product/892_23.aspx
It goes to Page.aspx?m=13&c=892&i=23 (eg category 892 and item 23)
The categoryID and productID can be any number of digits, that is why I have put in the '_' so I can see where one ends and the other starts.
What I'm not sure about is how to create the expression that will split them up��
Any help would be great. Thanks
Thanks for that, that worked first time...
I'm sorry to hyjack my own thread but I have one last question.
I have the following site structure:
SiteRoot/Page.aspx
Page.aspx loads other content pages (ascx) into it based on parameters passed in the querystring.
Eg. Page.aspx?m=1&i=1 would display the "News" module (moduleID=1) and news item 1 (newsID=1)
This works fine. I want to implement URLrewriting. I have followed this articlehttp://msdn.microsoft.com/library/?url=/library/en-us/dnaspp/html/urlrewriting.asp and have hit a problem.
I have set up in my web.config file rules:
<RewriterRule>
___<LookFor>~/News/(\w)\.aspx</LookFor>
___<SendTo>~/Page.aspx?m=1&i=$1</SendTo>
</RewriterRule>
This works fine so when I type MySite/News/1.aspx into the browser it rewrites to MySite/Page.aspx?m=1&i=1 and shows the page.
The problem is the images on the News Item page. They have <img src='images/image1.jpg'> this shows fine on MySite/Page.aspx?m=1&i=1 (Page.aspx is on the root). However when I go to MySite/News/1.aspx, the source for the image is broken. It is now looking for the images folder in the News folder which does not exist.
Do I have to put <img src="http://pics.10026.com/?src=~/images/image.jpg" runat='server'/> on every image reference, or is there another way around this.
Thanks again
Yes, I approved your new thread wherein you asked the same question.ricc wrote:
The problem is the images on the News Item page. They have <img src='images/image1.jpg'> this shows fine on MySite/Page.aspx?m=1&i=1 (Page.aspx is on the root). However when I go to MySite/News/1.aspx, the source for the image is broken. It is now looking for the images folder in the News folder which does not exist. Do I have to put <img src="http://pics.10026.com/?src=~/images/image.jpg" runat='server'/> on every image reference, or is there another way around this.