Click here to Skip to main content
15,911,711 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to get Country List with Two-letter country codes? Pin
Bernhard Hiller26-Feb-10 0:04
Bernhard Hiller26-Feb-10 0:04 
Questionsocket Pin
aurelcly23-Feb-10 22:35
aurelcly23-Feb-10 22:35 
AnswerRe: socket Pin
Richard MacCutchan24-Feb-10 1:24
mveRichard MacCutchan24-Feb-10 1:24 
AnswerRe: socket Pin
PIEBALDconsult24-Feb-10 9:27
mvePIEBALDconsult24-Feb-10 9:27 
QuestionDeleting an occurance of a string Pin
muka6623-Feb-10 22:20
muka6623-Feb-10 22:20 
AnswerRe: Deleting an occurance of a string Pin
OriginalGriff23-Feb-10 22:39
mveOriginalGriff23-Feb-10 22:39 
GeneralRe: Deleting an occurance of a string Pin
muka6624-Feb-10 1:28
muka6624-Feb-10 1:28 
GeneralRe: Deleting an occurance of a string Pin
OriginalGriff24-Feb-10 4:35
mveOriginalGriff24-Feb-10 4:35 
First off, when you post code fragments here, use the "code block" widget - it preserves formatting and make it easier to read.
Next, I think you need to read up a bit on Regular expressions! Get a copy of expresso - it helps you to understand what they are doing, and to create them.
Congratulations BTW on putting exception handling in! Well done - it is so easily forgotten.
protected void Page_Load(object sender, EventArgs e)
    {
    Regex removeImgTag = new Regex(@"\<img.*?(/>|</img>)", RegexOptions.Singleline);
    try
        {
        string mine = Server.UrlDecode(Request.QueryString["mine"]);
        string contents = File.ReadAllText(Server.MapPath(mine));
        string myContents = removeImgTag.Replace(contents, " ");
        lbldisplay.Text  = myContents; //Display the data without any pictures.
        }
    catch (Exception ex)
        {
        lblerror.Text = ex.Message;
        }
    }

Several changes from yours:
1) Don't make variables class scope unless you need them for the whole class - if they are only needed in a method, they should be local to the method.
2) Use sensible names for variables - it helps later when you will be dealing with lots of them!
3) The RegexOptions.SingleLine specifies that matches can cross line boundaries.
4) You don't need to open a file if you just want to read the whole thing - just use the File.ReadAllText method and it will do all the work.
5) You don't need to check if any matches exist - the Replace method will do that for you.

And voila! The HTML no longer has img tags in it.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace

C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

GeneralRe: Deleting an occurance of a string Pin
OriginalGriff24-Feb-10 4:37
mveOriginalGriff24-Feb-10 4:37 
AnswerRe: Deleting an occurance of a string Pin
Ravi Bhavnani24-Feb-10 7:44
professionalRavi Bhavnani24-Feb-10 7:44 
QuestionAcquireReaderLock Problems Pin
Sandy-Lee23-Feb-10 22:07
Sandy-Lee23-Feb-10 22:07 
AnswerRe: AcquireReaderLock Problems Pin
Richard MacCutchan24-Feb-10 1:29
mveRichard MacCutchan24-Feb-10 1:29 
Questionconnecting to telnet and executing perl script [modified] Pin
l.laxmikant23-Feb-10 21:49
l.laxmikant23-Feb-10 21:49 
AnswerRe: connecting to telnet and executing perl script Pin
Richard MacCutchan23-Feb-10 21:55
mveRichard MacCutchan23-Feb-10 21:55 
GeneralRe: connecting to telnet and executing perl script Pin
l.laxmikant23-Feb-10 22:00
l.laxmikant23-Feb-10 22:00 
GeneralRe: connecting to telnet and executing perl script Pin
Pete O'Hanlon23-Feb-10 22:28
mvePete O'Hanlon23-Feb-10 22:28 
GeneralRe: connecting to telnet and executing perl script Pin
l.laxmikant23-Feb-10 22:58
l.laxmikant23-Feb-10 22:58 
GeneralRe: connecting to telnet and executing perl script Pin
Pete O'Hanlon23-Feb-10 23:41
mvePete O'Hanlon23-Feb-10 23:41 
GeneralRe: connecting to telnet and executing perl script Pin
l.laxmikant24-Feb-10 0:22
l.laxmikant24-Feb-10 0:22 
GeneralRe: connecting to telnet and executing perl script Pin
Richard MacCutchan24-Feb-10 1:32
mveRichard MacCutchan24-Feb-10 1:32 
GeneralRe: connecting to telnet and executing perl script Pin
PIEBALDconsult24-Feb-10 9:33
mvePIEBALDconsult24-Feb-10 9:33 
AnswerRe: connecting to telnet and executing perl script [modified] Pin
PIEBALDconsult24-Feb-10 3:59
mvePIEBALDconsult24-Feb-10 3:59 
AnswerRe: connecting to telnet and executing perl script Pin
PIEBALDconsult1-Mar-10 4:16
mvePIEBALDconsult1-Mar-10 4:16 
AnswerRe: connecting to telnet and executing perl script Pin
PIEBALDconsult4-Mar-10 6:43
mvePIEBALDconsult4-Mar-10 6:43 
QuestionError Code 17 from RegReplaceKey ?? Pin
ub3rst4r23-Feb-10 19:30
ub3rst4r23-Feb-10 19:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.