Showing posts with label strip. Show all posts
Showing posts with label strip. Show all posts

Saturday, March 24, 2012

Strip characters from string

Hi, I want the user to be able to enter any form of number in my price textbox and I will automatically strip anything that is not an integer.

I obviously can't mand a string.replace for every character, so is there a way to use a regexp to say anything that isnt 0-9?

Thanks, Davehello, u can add a validation control to the textbox with the following:

[0-9]+

this way, they can enter any number they want.
But I don't want to have to restrict it like that. Many people will enter different formats for a price. I want them to be able to use '$' or ',' or whatever and have it stripped on the backend.

I am looking at regex.replace, but I can't get it to work yet.
well,
maybe u can allow them to enter any number or character and the loop through an array of all alphabets and eleminate all not needed characters !!!
I can offer you a commercial solution. My productProfessional Validation And More includes IntegerTextBox, CurrencyTextBox, and DecimalTextBox fields. They handle the filtering of illegal keystrokes, reformatting as the user exits the field, and supply you with the actual numeric value (an integer or Double property) on the server side.

Strip HTML from Text

Is there an easy way to strip HTML tags from Text to get just the plain
text?
I am using a program called FreeTextBox that lets you format Text in a
TextBox. It does this by adding HTML tags (<b>, <u>,<span> etc) to the
code.
The problem is that it is a problem since I am putting the text in a
varChar(8000). The HTML adds a lot characters to the text. I can change
this to a Text field in Sql, but you can do a FullText search on a Text
field (plus I don't really want the tags in a Text Search).
Is there some filtering mechanism that would strip the HTML from a text
field?
Thanks,
TomHere's a complete sample :
http://www.experience247.com/srcvie...tmlIn.cs&font=3
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:%23UjtGFlPGHA.1580@.TK2MSFTNGP09.phx.gbl...
> Is there an easy way to strip HTML tags from Text to get just the plain te
xt?
> I am using a program called FreeTextBox that lets you format Text in a Tex
tBox. It does this by
> adding HTML tags (<b>, <u>,<span> etc) to the code.
> The problem is that it is a problem since I am putting the text in a varCh
ar(8000). The HTML adds
> a lot characters to the text. I can change this to a Text field in Sql, b
ut you can do a FullText
> search on a Text field (plus I don't really want the tags in a Text Search
).
> Is there some filtering mechanism that would strip the HTML from a text fi
eld?
> Thanks,
> Tom
>
That does what I was looking for.
Thanks,
Tom
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:OMXrAJlPGHA.4952@.TK2MSFTNGP09.phx.gbl...
> Here's a complete sample :
> http://www.experience247.com/srcvie...tmlIn.cs&font=3
>
> Juan T. Llibre, asp.net MVP
> aspnetfaq.com : http://www.aspnetfaq.com/
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en espaol : http://asp.net.do/foros/
> ===================================
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:%23UjtGFlPGHA.1580@.TK2MSFTNGP09.phx.gbl...
>

Strip HTML from Text

Is there an easy way to strip HTML tags from Text to get just the plain
text?

I am using a program called FreeTextBox that lets you format Text in a
TextBox. It does this by adding HTML tags (<b>, <u>,<span> etc) to the
code.

The problem is that it is a problem since I am putting the text in a
varChar(8000). The HTML adds a lot characters to the text. I can change
this to a Text field in Sql, but you can do a FullText search on a Text
field (plus I don't really want the tags in a Text Search).

Is there some filtering mechanism that would strip the HTML from a text
field?

Thanks,

TomHere's a complete sample :

http://www.experience247.com/srcvie...tmlIn.cs&font=3

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:%23UjtGFlPGHA.1580@.TK2MSFTNGP09.phx.gbl...
> Is there an easy way to strip HTML tags from Text to get just the plain text?
> I am using a program called FreeTextBox that lets you format Text in a TextBox. It does this by
> adding HTML tags (<b>, <u>,<span> etc) to the code.
> The problem is that it is a problem since I am putting the text in a varChar(8000). The HTML adds
> a lot characters to the text. I can change this to a Text field in Sql, but you can do a FullText
> search on a Text field (plus I don't really want the tags in a Text Search).
> Is there some filtering mechanism that would strip the HTML from a text field?
> Thanks,
> Tom
That does what I was looking for.

Thanks,

Tom
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:OMXrAJlPGHA.4952@.TK2MSFTNGP09.phx.gbl...
> Here's a complete sample :
> http://www.experience247.com/srcvie...tmlIn.cs&font=3
>
> Juan T. Llibre, asp.net MVP
> aspnetfaq.com : http://www.aspnetfaq.com/
> asp.net faq : http://asp.net.do/faq/
> foros de asp.net, en espaol : http://asp.net.do/foros/
> ===================================
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:%23UjtGFlPGHA.1580@.TK2MSFTNGP09.phx.gbl...
>> Is there an easy way to strip HTML tags from Text to get just the plain
>> text?
>>
>> I am using a program called FreeTextBox that lets you format Text in a
>> TextBox. It does this by adding HTML tags (<b>, <u>,<span> etc) to the
>> code.
>>
>> The problem is that it is a problem since I am putting the text in a
>> varChar(8000). The HTML adds a lot characters to the text. I can change
>> this to a Text field in Sql, but you can do a FullText search on a Text
>> field (plus I don't really want the tags in a Text Search).
>>
>> Is there some filtering mechanism that would strip the HTML from a text
>> field?
>>
>> Thanks,
>>
>> Tom
>>

strip non-numeric characters

Is there simple way to take a string that should be all numeric (like a
credit card number) and strip out anything that isn't a digit? In the past
I've done this in VFP using the IsDigit() function, looping through each
character. It was a little awkward, but worked. Is there something similar,
or better for vb.net?

Thanks!

MattThe IsNumeric function should fill the bill...

Dim MyVar As Object
Dim MyCheck As Boolean
' ...
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False.

Regards,
January Smith

"MattB" <somedudeus@.yahoo.com> wrote in message
news:2hmemqFen4c9U1@.uni-berlin.de...
> Is there simple way to take a string that should be all numeric (like a
> credit card number) and strip out anything that isn't a digit? In the past
> I've done this in VFP using the IsDigit() function, looping through each
> character. It was a little awkward, but worked. Is there something
similar,
> or better for vb.net?
> Thanks!
> Matt
I would try Regex. You can look for \d and pull all instances, then concat
back the resulting array. There are a couple of other ways to work with
this.

Note that VB.NET still has IsNumber() or IsNumeric() [forget which one], so
you can still loop and test, if you want to go with VB.NET.

Another option is convert to a char array and test the numeric value of each
char. The ASCII value for numbers is extremely predictable.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"MattB" <somedudeus@.yahoo.com> wrote in message
news:2hmemqFen4c9U1@.uni-berlin.de...
> Is there simple way to take a string that should be all numeric (like a
> credit card number) and strip out anything that isn't a digit? In the past
> I've done this in VFP using the IsDigit() function, looping through each
> character. It was a little awkward, but worked. Is there something
similar,
> or better for vb.net?
> Thanks!
> Matt
You can use the Regex.Replace method to check for any characters (\w) and replace them with an empty string. The result that would come out is a string that is all numeric.

strip non-numeric characters

Is there simple way to take a string that should be all numeric (like a
credit card number) and strip out anything that isn't a digit? In the past
I've done this in VFP using the IsDigit() function, looping through each
character. It was a little awkward, but worked. Is there something similar,
or better for vb.net?
Thanks!
MattThe IsNumeric function should fill the bill...
Dim MyVar As Object
Dim MyCheck As Boolean
' ...
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False.
Regards,
January Smith
"MattB" <somedudeus@.yahoo.com> wrote in message
news:2hmemqFen4c9U1@.uni-berlin.de...
> Is there simple way to take a string that should be all numeric (like a
> credit card number) and strip out anything that isn't a digit? In the past
> I've done this in VFP using the IsDigit() function, looping through each
> character. It was a little awkward, but worked. Is there something
similar,
> or better for vb.net?
> Thanks!
> Matt
>
I would try Regex. You can look for \d and pull all instances, then concat
back the resulting array. There are a couple of other ways to work with
this.
Note that VB.NET still has IsNumber() or IsNumeric() [forget which one],
so
you can still loop and test, if you want to go with VB.NET.
Another option is convert to a char array and test the numeric value of each
char. The ASCII value for numbers is extremely predictable.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
****************************************
********
Think Outside the Box!
****************************************
********
"MattB" <somedudeus@.yahoo.com> wrote in message
news:2hmemqFen4c9U1@.uni-berlin.de...
> Is there simple way to take a string that should be all numeric (like a
> credit card number) and strip out anything that isn't a digit? In the past
> I've done this in VFP using the IsDigit() function, looping through each
> character. It was a little awkward, but worked. Is there something
similar,
> or better for vb.net?
> Thanks!
> Matt
>
You can use the Regex.Replace method to check for any characters (\w) and re
place them with an empty string. The result that would come out is a string
that is all numeric.

Strip html tags from listbox

I've been looking around with no luck for the way to get rid of the html tags from showing in a listbox being popullated from the db.

Where have I not looked for this solution?

Thanks all,

ZathYou could always htmlEncode the contents of the listbox. That wouldn't strip away the tags, just convert them. For example <tag> would become <tag>.

You could always write a function that searches for the "<" and ">" characters and strips them off.

Jeff
Yea, thought of that.

It's just in PHP, it's something easy like strip_html or something like that...
Thought and searched for something similar in .Net

Zath

Strip space before page rendering

Is there any benefit to stripping all the space from the page before
rendering by overriding the page render and using the htmltextwriter and
stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
that may site's source code is like this. Is this because it is better for
the browser or harder for someone to be able to read it. Or maybe there is a
method or command to do this automatically?

Any thoughts are appreciated.

Mikesaves bandwidth mainly...

"vMike" <Michael.George@.gewarren.com.nospam> wrote in message
news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> Is there any benefit to stripping all the space from the page before
> rendering by overriding the page render and using the htmltextwriter and
> stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
> that may site's source code is like this. Is this because it is better for
> the browser or harder for someone to be able to read it. Or maybe there is
a
> method or command to do this automatically?
> Any thoughts are appreciated.
> Mike
I don't think there is a way to do it automatically, but it's simple enough
to implement.

This is the approach I use:

I have a base class derived from System.Web.UI.Page and override Render

namespace DoNot.Invade.MySpace
{
class Page : System.Web.UI.Page
{
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);

base.Render (hw);

string html = sb.ToString();

html = html.Replace(Environment.NewLine, string.Empty);
html = html.Replace("\n", string.Empty); // This may be redundant
html = html.Replace("\t", string.Empty);

writer.Write(html);
}
}
}

Hope this helps
Brian W

"vMike" <Michael.George@.gewarren.com.nospam> wrote in message
news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> Is there any benefit to stripping all the space from the page before
> rendering by overriding the page render and using the htmltextwriter and
> stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
> that may site's source code is like this. Is this because it is better for
> the browser or harder for someone to be able to read it. Or maybe there is
a
> method or command to do this automatically?
> Any thoughts are appreciated.
> Mike
Thanks, I had something similar to that. The only thing I had to do was do
remove the <!-- that asp puts before the javascipt for postback because when
I removed the rest of the line is caused an error. But I wonder is stripping
the space make the page display any quicker in the browser as I image there
is a small amount of overhead on the server side.

"Brian W" <brianw@.gold_death_2_spam_rush.com> wrote in message
news:%23zf8QjxnDHA.1488@.TK2MSFTNGP12.phx.gbl...
> I don't think there is a way to do it automatically, but it's simple
enough
> to implement.
> This is the approach I use:
> I have a base class derived from System.Web.UI.Page and override Render
> namespace DoNot.Invade.MySpace
> {
> class Page : System.Web.UI.Page
> {
> protected override void Render(HtmlTextWriter writer)
> {
> StringBuilder sb = new StringBuilder();
> StringWriter sw = new StringWriter(sb);
> HtmlTextWriter hw = new HtmlTextWriter(sw);
> base.Render (hw);
> string html = sb.ToString();
> html = html.Replace(Environment.NewLine, string.Empty);
> html = html.Replace("\n", string.Empty); // This may be redundant
> html = html.Replace("\t", string.Empty);
> writer.Write(html);
> }
> }
> }
> Hope this helps
> Brian W
> "vMike" <Michael.George@.gewarren.com.nospam> wrote in message
> news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> > Is there any benefit to stripping all the space from the page before
> > rendering by overriding the page render and using the htmltextwriter and
> > stringbuilder to strip linefeeds, tabs and extra space etc. I have
noticed
> > that may site's source code is like this. Is this because it is better
for
> > the browser or harder for someone to be able to read it. Or maybe there
is
> a
> > method or command to do this automatically?
> > Any thoughts are appreciated.
> > Mike
Brian W wrote:

> I don't think there is a way to do it automatically, but it's simple enough
> to implement.
> This is the approach I use:
> I have a base class derived from System.Web.UI.Page and override Render
> namespace DoNot.Invade.MySpace
> {
> class Page : System.Web.UI.Page
> {
> protected override void Render(HtmlTextWriter writer)
> {
> StringBuilder sb = new StringBuilder();
> StringWriter sw = new StringWriter(sb);
> HtmlTextWriter hw = new HtmlTextWriter(sw);
> base.Render (hw);
> string html = sb.ToString();
> html = html.Replace(Environment.NewLine, string.Empty);
> html = html.Replace("\n", string.Empty); // This may be redundant
> html = html.Replace("\t", string.Empty);
> writer.Write(html);
> }
> }
> }

You'll want to be careful with simplistic code like this. There are
times when whitespace and newlines are significant, such as text inside
of a <pre> element or script code.

> Hope this helps
> Brian W
> "vMike" <Michael.George@.gewarren.com.nospam> wrote in message
> news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
>>Is there any benefit to stripping all the space from the page before
>>rendering by overriding the page render and using the htmltextwriter and
>>stringbuilder to strip linefeeds, tabs and extra space etc. I have noticed
>>that may site's source code is like this. Is this because it is better for
>>the browser or harder for someone to be able to read it. Or maybe there is
> a
>>method or command to do this automatically?
>>
>>Any thoughts are appreciated.
>>
>>Mike
>>
>>

--
mikeb
True, I guess I should have mentioned that. Since the site I'm currently
working on doesn't use <pre> I don't worry about it. And what I have written
can be expanded upon to handle these situations.

There are other cases where this is a problem too. Such as the following:

<p>
This is
some text
</p
will produce the following output:

This issome text

For me, though, I just edit the html and make sure there is also a space
before the newline.

Regards
Brian W

"mikeb" <mailbox.google@.mailnull.com> wrote in message
news:%23YdMB$xnDHA.1672@.TK2MSFTNGP09.phx.gbl...
> Brian W wrote:
> > I don't think there is a way to do it automatically, but it's simple
enough
> > to implement.
> > This is the approach I use:
> > I have a base class derived from System.Web.UI.Page and override Render
> > namespace DoNot.Invade.MySpace
> > {
> > class Page : System.Web.UI.Page
> > {
> > protected override void Render(HtmlTextWriter writer)
> > {
> > StringBuilder sb = new StringBuilder();
> > StringWriter sw = new StringWriter(sb);
> > HtmlTextWriter hw = new HtmlTextWriter(sw);
> > base.Render (hw);
> > string html = sb.ToString();
> > html = html.Replace(Environment.NewLine, string.Empty);
> > html = html.Replace("\n", string.Empty); // This may be redundant
> > html = html.Replace("\t", string.Empty);
> > writer.Write(html);
> > }
> > }
> > }
> You'll want to be careful with simplistic code like this. There are
> times when whitespace and newlines are significant, such as text inside
> of a <pre> element or script code.
>
> > Hope this helps
> > Brian W
> > "vMike" <Michael.George@.gewarren.com.nospam> wrote in message
> > news:bnpsnk$rfa$1@.ngspool-d02.news.aol.com...
> >>Is there any benefit to stripping all the space from the page before
> >>rendering by overriding the page render and using the htmltextwriter and
> >>stringbuilder to strip linefeeds, tabs and extra space etc. I have
noticed
> >>that may site's source code is like this. Is this because it is better
for
> >>the browser or harder for someone to be able to read it. Or maybe there
is
> > a
> >>method or command to do this automatically?
> >>
> >>Any thoughts are appreciated.
> >>
> >>Mike
> >>
> >>
> --
> mikeb

Strip out JavaScript, etc.

I need to disply user-entered HTML on the screen. Needless to say, this has led to problems.

Is there any library that will strip out JavaScript, Input tags, etc. from HTML, leaving behind only reasonably safe tags?

Note: For reasons I can't control, I cannot filter out the garbage on input. I need to do it when the info is displayed.

Jonathan Allen

Hi,

you could probably make good use of the Anti Cross Site Scripting library:http://forums.asp.net/1107.aspx.

Grz, Kris.


Correct me if I'm wrong, but that doesn't look like it will work.

What I need to do is strip out only unsafe HTML. I have to be able to leave the other HTML behind. All the methods I saw in the docs are about encoding the output, which is the wrong thing to do.

Jonathan


I would attempt to do this using regular expressions. Are you familiar with regular expressions?


Regular expressions are not really an answer. Besides the fact that regular expressions are totally unsuitable for parsing something as complex as HTML, you still have to figure out for yourself what is safe and what isn't.

What I am looking for a library that understands the difference between safe and unsafe HTML, and is capable of filtering out the latter.


Other than javascript, what would be an example of some unsafe HTML?


Input tags for one.

What happens is that users email us HTML copied and pasted from other sites. Sometimes this email contains input tags. Especially troubling from a stability standpoint is when the input tag has the idea __viewstate. Needless to say, this breaks the real viewstate on the page.

Really any Form tag is also a risk. Though no likely in our case, one doesn't want users creating bogus forms that post their information to email or a web site out of your control.


Well, from what I can understand, your creating an even stronger case for using regular expressions. I feel I'm not completely understanding the scenario properly.

It sounds like you'll need to think about what you consider to be unsafe, and create a list. Armed with this, you'll need to create a list of expressions to match and remove (or replace with nothing).

I'm still not 100% on how/why you need to do this though? Can you talk me through an example - or is there a URL you can direct me too?

From what you've said, I'm assuming that people are filling in a form which emails you the code they entered (or something similar), and that's causing the problem? Perhaps you could try using the depricated <xmp> ... </xmp> tag? (strictly speaking you shouldn't though, I know.)

strip out html

Hello

anybody knows how i can strip out the html from a control's innerhtml to show only the relevant text? i.e
<span id="test1" runat="server"><a href="http://links.10026.com/?link=test1.htm">abcde</a><b>blah</b></span

so that on my server side code, somehow i would get "abcde blah"?
thanks!FYI... you wouldn't get "abcde blah" you'd get "abcdeblah"
I dont think there is an auto-way to do this but just look for the > and <
and use the Substring in a recursive function

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com

"newbie" <anonymous@.discussions.microsoft.com> wrote in message
news:799A9C64-BAB4-45D1-80EC-580EA1E98D3F@.microsoft.com...
> Hello,
> anybody knows how i can strip out the html from a control's innerhtml to
show only the relevant text? i.e.
> <span id="test1" runat="server"><a
href="test1.htm">abcde</a><b>blah</b></span>
> so that on my server side code, somehow i would get "abcde blah"??
> thanks!
"newbie" <anonymous@.discussions.microsoft.com> wrote in message
news:799A9C64-BAB4-45D1-80EC-580EA1E98D3F@.microsoft.com...
> Hello,
> anybody knows how i can strip out the html from a control's innerhtml to
show only the relevant text? i.e.
> <span id="test1" runat="server"><a
href="test1.htm">abcde</a><b>blah</b></span>
> so that on my server side code, somehow i would get "abcde blah"??
> thanks!

Provided it is xhtml compliant (i.e. no unclosed tags and case sensitive),
why not read the contents of each node, with an XmlTextReader? Then
concatenate each node's value using a StringBuilder.

ms-help://MS.NETFrameworkSDK/cpref/html/frlrfSystemXmlXmlTextReaderClassctor
Topic.htm

...and see the example at bottom for how to use the XmlTextReader.

R.

strip out any html code from textbox

Hi! I am looking for a way to stip out any html code if the user type in some html in the textbox. Thanks!!

If the ValidateRequest is turned on for a page then ASP.Net will automatically detect the HTML in the text box and throw an error.

ValidateRequest can be turned on in the Page directive.


use

yourString= Server.HtmlEncode(Trim(TxtBxManufactureProductID.Text))

or
yourString=HttpUtility.HtmlEncode(TxtBxManufactureProductID.Text)

yourString is a string variable


Use can use HTMLEncode as told previously, else if you want to completely remove HTML then you may user RegEx. <(?<tag>\w*)>(?<text>.*)</\k<tag>> , and replace them with some empty string.

I am not sure of the exact code, but you can replace HTML for sure.

Ankit


Hi! Thank you for the reply, I tried yourString=HttpUtility.HtmlEncode(TxtProfile.Text) and got an error ( a potentially dangerous request...)

And I also tried the one that has Trim,but it says that Trim doesn't exist in the current contest. Do I have to import a namespace for that? Thanks.


Thanks! I get a syntax error on the reguloar expression:

<asp:RegularExpressionValidatorID="RegularExpressionValidator1"runat="server"ControlToValidate="txtBusinessprofile"ValidationExpression="<(?<tag>\w*)>(?<text>.*)</\k<tag>>">Please do not incluse html code!</asp:RegularExpressionValidator>


<%@. Page Language="VB" MasterPageFile="AdminMasterPage.master" AutoEventWireup="false" Inherits="YYY" title="xxxx"ValidateRequest="false" Codebehind="YYY.aspx.vb" %>

you will have a line like above in your axpx file(the fist line)

write the ValidateRequest="false" there

Then also use codes in my previous replay


Do you know how to catch the exception that is thrown when ValidationRequest="true" and user inputs an html? I can see that this exception is fired much before the execution point ever comes the actual page's codebehind. I guess i could not even catch it in Application_Error.....

It will be actually nice to have something like this:

1. keep ValidationRequest="true"

2. Exception is thrown if user enters html or anything inside angular brackets

3. Error is caught at Page error handler and action is taken (display msg etc)

This will save remembering to validate for malicious input (or at least a scripting type of malicious input) in all the forms in all the pages...


Thanks for the tip! I have also read that it's not a good habit to set validaterequest to false cos of the script injection attacks that might arise...I had mine set to false for the page only and I need to make sure that all html code is stripped out of the textbox.

Strip Visual Studio META Tags Is Safe?

I have these in all of my pages:

<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5"
And I am wondering if it is safe to remove them after I compile the
ASP.NET application, or if it is possible to have VS.NET 2003 not put
them in my .aspx pages in the first place.

Thanks.meta tags are not rendered, they are only used to provide information to the
server and the client. They can be deleted at will, if you don't need them.
Removing the target schema and client script meta tags will remove some
intellisense features on the development environment, but nothing contained
in a meta tag will affect the rendering of the page itself.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"localhost" <primpilus@.cohort.ces> wrote in message
news:3ubf20p4i2t4k30u4je2hjmv5atl7g4e4v@.4ax.com...
>I have these in all of my pages:
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name=vs_defaultClientScript content="JavaScript">
> <meta name=vs_targetSchema
> content="http://schemas.microsoft.com/intellisense/ie5">
> And I am wondering if it is safe to remove them after I compile the
> ASP.NET application, or if it is possible to have VS.NET 2003 not put
> them in my .aspx pages in the first place.
> Thanks.
Hi Localhost,

Thanks for posting in the community!
From your description, you are wondering some infos on the <meta> tags
VS.NET has automatically put in the ASP.NET page when page is created and
whether it'll cause any problem if remove them, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, I agree to Chris's opinion, the meta tags commonly
tells web browsers basic host information about a site or the tools that
created the source files of the site. This information is also used by
search engines. For detailed info on the META tags, you may view the
following web references:

#META - Metadata
http://www.htmlhelp.com/reference/html40/head/meta.html

#HTML Tutorial -> META - Metadata
http://www.style-sheets.com/html_tutorial/head/meta.asp

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Stripping characters...

I'm trying to strip the characters from a text box...
but I only know how to apply it to text...
for example..

string fname = @dotnet.itags.org."*\John Doe";
string pattern = @dotnet.itags.org."^.*\\";
string name = Regex.Replace(fname, pattern," ");

but how can i do it for a passed variable...
like @dotnet.itags.org.Request.Form["fname"];

string fname = @dotnet.itags.org.Request.Form["fname"];
string pattern = @dotnet.itags.org."^.*\\";
string name = Regex.Replace(fname, pattern," ");

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.comHave you tried

string pattern = @."^.*\\";
string name = Regex.Replace(Request.Form["fname"], pattern," ");

--
Regards

John Timney
Microsoft MVP

"VJ" <vncntj@.hotmail.com> wrote in message
news:%23jugUr6GGHA.532@.TK2MSFTNGP15.phx.gbl...
> I'm trying to strip the characters from a text box...
> but I only know how to apply it to text...
> for example..
>
> string fname = @."*\John Doe";
> string pattern = @."^.*\\";
> string name = Regex.Replace(fname, pattern," ");
>
> but how can i do it for a passed variable...
> like @.Request.Form["fname"];
> string fname = @.Request.Form["fname"];
> string pattern = @."^.*\\";
> string name = Regex.Replace(fname, pattern," ");
> --
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com

Stripping characters...

I'm trying to strip the characters from a text box...
but I only know how to apply it to text...
for example..
string fname = @dotnet.itags.org."*\John Doe";
string pattern = @dotnet.itags.org."^.*\\";
string name = Regex.Replace(fname, pattern," ");
but how can i do it for a passed variable...
like @dotnet.itags.org.Request.Form["fname"];
string fname = @dotnet.itags.org.Request.Form["fname"];
string pattern = @dotnet.itags.org."^.*\\";
string name = Regex.Replace(fname, pattern," ");
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.comHave you tried
string pattern = @."^.*\\";
string name = Regex.Replace(Request.Form["fname"], pattern," ");
Regards
John Timney
Microsoft MVP
"VJ" <vncntj@.hotmail.com> wrote in message
news:%23jugUr6GGHA.532@.TK2MSFTNGP15.phx.gbl...
> I'm trying to strip the characters from a text box...
> but I only know how to apply it to text...
> for example..
>
> string fname = @."*\John Doe";
> string pattern = @."^.*\\";
> string name = Regex.Replace(fname, pattern," ");
>
> but how can i do it for a passed variable...
> like @.Request.Form["fname"];
> string fname = @.Request.Form["fname"];
> string pattern = @."^.*\\";
> string name = Regex.Replace(fname, pattern," ");
> --
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com

stripping out html tags for plain txt email

I was wondering what the best way to strip the html tags off of a page and add vbclf and such for plain text emailing of web pages

if you could point me in the right direction it would be greatTo remove HTML tags from awell-formed document:
Converting HTML to Text
awesome what a life saver
now how could I change the code below so that it replaces the </p> and <br> with a _vbclrf or a plaintext line break and also how can I get it to remove all of the dead space I see a comment posted on the page you linked about doing it but no one actually does


Public Function StripTags(ByVal HTML As String) As String
' Removes tags from passed HTML
Dim objRegEx As _
System.Text.RegularExpressions.Regex
Return objRegEx.Replace(HTML, "<[^>]*>", "")
End Function

Try the following:
 Import System.Text.RegularExpressions

Public Function StripTags(ByVal HTML As String) As String
Dim cleanString As String = HTML
Dim objRegEx As Regex

' First, remove whitespace
objRegEx = New RegEx( "\s{2,}" )
cleanString = objRegEx.Replace( cleanString, " " )

' Second, replace HTML linebreaks with text line breaks
objRegEx = New RegEx( "((</p>)|(<br ?/?>))" )
cleanString = objRegEx.Replace( cleanString, System.Environment.NewLine )

' Third, clean up any occurrence of newline + space
objRegEx = New RegEx( "(^|\n) +" )
cleanString = objRegEx.Replace( cleanString, String.Empty)

' Finally, remove HTML tags
objRegEx = New RegEx( "<[^>]*?>" )
cleanString = objRegEx.Replace( cleanString, String.Empty)

Return cleanString
End Function

Stripping Needless Data From HttpContext.Current.Request.Form

I found this nice example of printing data to the default printer of the server when the submit button is clicked. But not sure how to strip out the names of the controls, etc.

Here is the code for those interested:

1Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)23 Dim yPos As Single = 2504 Dim leftMargin As Single = ev.MarginBounds.Left5 Dim topMargin As Single = ev.MarginBounds.Top6 Dim printFont = New Font("Arial", 10)78 Dim sb As StringBuilder = New StringBuilder()910 ' Page title and date/time.11 sb.Append("Maintenance Request")12 sb.Append(Environment.NewLine)13 sb.Append("DateTime: " + DateTime.Now.ToString() + Environment.NewLine)1415 ' Iterate submitted form fields and get field names.16 Dim fieldValue As String17 Dim fieldName As String1819 ' Exclude viewstate and submit button.20 For Each fieldName In HttpContext.Current.Request.Form21 Response.Write("Field Name: " & HttpContext.Current.Request.Form(fieldName) & "<br>")22 If fieldName = "__VIEWSTATE" Or fieldName = "Submit" Then2324 Else25 ' Get the field values.2627 fieldValue = HttpContext.Current.Request.Form(fieldName)2829 ' Add the field names and values to the page.30 ' Break the field values into 50 character segments so it will fit on the paper.31 ' Currently, this only accounts for fields of l50 characters or less.32 ' ISSUE: breaks in the middle of words instead of spaces3334 If fieldValue.Length > 100 Then35 sb.Append(fieldName + ": " + fieldValue.Substring(0, 50) + Environment.NewLine)36 sb.Append(" " + fieldValue.Substring(50, 50) + Environment.NewLine)37 sb.Append(" " + fieldValue.Substring(100, fieldValue.Length - 100) + Environment.NewLine)3839 ElseIf fieldValue.Length > 50 Then40 sb.Append(fieldName + ": " + fieldValue.Substring(0, 50) + Environment.NewLine)41 sb.Append(" " + fieldValue.Substring(50, fieldValue.Length - 50) + Environment.NewLine)42 Else43 sb.Append(fieldName + ": " + fieldValue + Environment.NewLine)4445 End If4647 End If4849 Next50 ev.Graphics.DrawString(sb.ToString(), printFont, Brushes.Black, leftMargin, yPos, New StringFormat())5152 End Sub
 
There has to be a better way. Any ideas?
Figured it out. Instead of using HttpContext.Current.Request.Form, I am just using the explicit names of the controls and appending the values to the stringbuilder. If anyone needs help with this, please feel free to contact me.Big Smile

stripping tags from source on render

Hi,
What way could I strip certain tags (like HTML comments) from the HTML being
delivered to the client? I don't mean what regexp to use, but where do I
put this stripping code? I'm thinking something in the Global.asax, but I
can't find any reference to it having a Render or PreRender event or how to
tie into them if I did! I'd ideally like some help along the lines of:

1 - Where to put the code
2 - example of how to alter the source being delivered to the client

Thanks,
LanceHi Lance:

You could use a Response.Filter, like the one in this article:
http://www.codeproject.com/aspnet/R...pacesAspNet.asp

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 17 Jun 2005 11:43:50 +0100, "Lance"
<lance@.[nospam]keayweb.com> wrote:

>Hi,
>What way could I strip certain tags (like HTML comments) from the HTML being
>delivered to the client? I don't mean what regexp to use, but where do I
>put this stripping code? I'm thinking something in the Global.asax, but I
>can't find any reference to it having a Render or PreRender event or how to
>tie into them if I did! I'd ideally like some help along the lines of:
>1 - Where to put the code
>2 - example of how to alter the source being delivered to the client
>Thanks,
>Lance
Hi Lance,

I'd look at the Page.Render event. This takes an HtmlTextWriter parameter
where you can modify the contents before calling the base.Render method.

HTH
--
Ian Lane

"Lance" wrote:

> Hi,
> What way could I strip certain tags (like HTML comments) from the HTML being
> delivered to the client? I don't mean what regexp to use, but where do I
> put this stripping code? I'm thinking something in the Global.asax, but I
> can't find any reference to it having a Render or PreRender event or how to
> tie into them if I did! I'd ideally like some help along the lines of:
> 1 - Where to put the code
> 2 - example of how to alter the source being delivered to the client
> Thanks,
> Lance
>
Thanks! I thought i had seen it somewhere on good 'ol codeproject!

"Scott Allen" <scott@.nospam.odetocode.com> wrote in message
news:k3s5b1drg28qbudj23ggjs1l8r861cuqhh@.4ax.com...
> Hi Lance:
> You could use a Response.Filter, like the one in this article:
> http://www.codeproject.com/aspnet/R...pacesAspNet.asp
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
> On Fri, 17 Jun 2005 11:43:50 +0100, "Lance"
> <lance@.[nospam]keayweb.com> wrote:
> >Hi,
> >What way could I strip certain tags (like HTML comments) from the HTML
being
> >delivered to the client? I don't mean what regexp to use, but where do I
> >put this stripping code? I'm thinking something in the Global.asax, but
I
> >can't find any reference to it having a Render or PreRender event or how
to
> >tie into them if I did! I'd ideally like some help along the lines of:
> >1 - Where to put the code
> >2 - example of how to alter the source being delivered to the client
> >Thanks,
> >Lance
I'd have to call the code from every page using this method, right? If I
could call it from one location (global.asax) that would be great!

"Ian Lane .enizin.net>" <ian@.<nospam> wrote in message
news:329AC863-65C0-41DC-B99E-2C47F83EA16F@.microsoft.com...
> Hi Lance,
> I'd look at the Page.Render event. This takes an HtmlTextWriter parameter
> where you can modify the contents before calling the base.Render method.
> HTH
> --
> Ian Lane
>
> "Lance" wrote:
> > Hi,
> > What way could I strip certain tags (like HTML comments) from the HTML
being
> > delivered to the client? I don't mean what regexp to use, but where do
I
> > put this stripping code? I'm thinking something in the Global.asax, but
I
> > can't find any reference to it having a Render or PreRender event or how
to
> > tie into them if I did! I'd ideally like some help along the lines of:
> > 1 - Where to put the code
> > 2 - example of how to alter the source being delivered to the client
> > Thanks,
> > Lance

Stripping out unwanted characters

How can I strip out unwanted characters in a string before updating the
database? For instance, in names & addresses in our client table, we want
only letters and numbers, no punctuation. Is there a way to do this?HI,

Use regular expression to remove unwanted characters and then send the
string to database. Here is a sample code to remove non-alphanumerical
characters from a string.

hoep this will help you...

public static void Main()

{

/*Reg expression to find non-alphanumeric characters*/

string pattern = @."[^A-Za-z0-9]";

/*include System.Text.RegularExpressions name space*/

Regex rgx = new Regex(pattern);

string inputStr = "ab$!Cd&%$gf!";

/*Replace non-alphanumeric characters with space*/

string outputStr = rgx.Replace(inputStr, " ");

Console.WriteLine("Output string:"+ outputStr);

}

Cheers
Vinu

"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?
Function StripUnwantedChars(ByVal StringToStrip AsString) AsString
Dim stripped AsString
If StringToStrip <> "" Then
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)
Return stripped
Else
Return ""
EndIf
EndFunction

Note : insert all the characters you want to strip inside the quotes.

For example, instead of :
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)

use :
stripped = Regex.Replace(StringToStrip, "<!#(.|\n)+?>", String.Empty)

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"et" <eagletender2001@.yahoo.com> wrote in message news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the database? For instance,
> in names & addresses in our client table, we want only letters and numbers, no punctuation. Is
> there a way to do this?
Thanks, everyone, that's exactly what I was looking for.

"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?

Stripping out unwanted characters

How can I strip out unwanted characters in a string before updating the
database? For instance, in names & addresses in our client table, we want
only letters and numbers, no punctuation. Is there a way to do this?HI,
Use regular expression to remove unwanted characters and then send the
string to database. Here is a sample code to remove non-alphanumerical
characters from a string.
hoep this will help you...
public static void Main()
{
/*Reg expression to find non-alphanumeric characters*/
string pattern = @."[^A-Za-z0-9]";
/*include System.Text.RegularExpressions name space*/
Regex rgx = new Regex(pattern);
string inputStr = "ab$!Cd&%$gf!";
/*Replace non-alphanumeric characters with space*/
string outputStr = rgx.Replace(inputStr, " ");
Console.WriteLine("Output string:"+ outputStr);
}
Cheers
Vinu
"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?
>
Function StripUnwantedChars(ByVal StringToStrip AsString) AsString
Dim stripped AsString
If StringToStrip <> "" Then
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)
Return stripped
Else
Return ""
EndIf
EndFunction
Note : insert all the characters you want to strip inside the quotes.
For example, instead of :
stripped = Regex.Replace(StringToStrip, "<(.|\n)+?>", String.Empty)
use :
stripped = Regex.Replace(StringToStrip, "<!#(.|\n)+?>", String.Empty)
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"et" <eagletender2001@.yahoo.com> wrote in message news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl
..
> How can I strip out unwanted characters in a string before updating the da
tabase? For instance,
> in names & addresses in our client table, we want only letters and numbers
, no punctuation. Is
> there a way to do this?
>
Thanks, everyone, that's exactly what I was looking for.
"et" <eagletender2001@.yahoo.com> wrote in message
news:ODVkXK7NGHA.668@.TK2MSFTNGP11.phx.gbl...
> How can I strip out unwanted characters in a string before updating the
> database? For instance, in names & addresses in our client table, we want
> only letters and numbers, no punctuation. Is there a way to do this?
>