Treceți la conținutul principal

basic parser html cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace tinyHTMLparser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int linesNr = 0;
        int startPos = 0; 
        int endPos = 0;
        String selectionText = "";

        int startPosBetween = 0;
        int endPosBetween = 0;
        String selectionTextBetween = "";

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
             

            this.openFileFialog1.Filter = "All Files|*.*";
            if (this.openFileFialog1.ShowDialog() == DialogResult.OK)
            {
                this.OpenFile(this.openFileFialog1.FileName);
            }
        }
        private void OpenFile(string filename)
        {
            
            
            FileInfo fileInfo = new FileInfo(filename);
            
            using (StreamReader sr = fileInfo.OpenText()) 
        {
            string s = "";
            while ((s = sr.ReadLine()) != null) 
            {
                
                this.textBox1.AppendText(s);
                this.textBox1.AppendText(Environment.NewLine);
                linesNr++;
            }
        }

        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {

              this.saveFileDialog1.Filter = "All Files|*.parsed";
            if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.SaveFile(this.saveFileDialog1.FileName);
            }


            
        }

        private void SaveFile(string filename)
        {



            string path = filename;
                FileInfo fi = new FileInfo(path);

                if (!fi.Exists)
                {
                    //Create the file.
                    fi.Create();
                }

                // Open the stream for writing.
                using (FileStream fs = fi.OpenWrite())
                {
                    //Byte[] info = new UTF8Encoding(true).GetBytes("This is to test the OpenWrite method.");
                    Byte[] info = new UTF8Encoding(true).GetBytes(selectionTextBetween);
                    // Add some information to the file.
                    fs.Write(info, 0, info.Length);
                }

                /* Open the stream and read it back.
                using (FileStream fs = fi.OpenRead())
                {
                    byte[] b = new byte[1024];
                    UTF8Encoding temp = new UTF8Encoding(true);

                    while (fs.Read(b, 0, b.Length) > 0)
                    {
                        //Console.WriteLine(temp.GetString(b));
                    }
                }
                 */

        }
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
           
        }

        private void parseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.SelectionStart = 0;
            int selIndex = 0;     

            String strStart = "<a href=\"#\"><strong>";
            String strEnd = "</strong></a>";
             
            for(int i = 0 ; i<=textBox1.Text.Length;i++){
                textBox1.SelectionStart = i;
                selIndex = i;
                textBox1.SelectionLength = strStart.Length;
                if (textBox1.SelectedText == strStart)
                {
                            
                        startPos = i;
                        startPosBetween = i + strStart.Length;
                            break;
                       
                   
                        }
                    }

            for (int j = selIndex+1; j <= textBox1.Text.Length; j++)
            {
                textBox1.SelectionStart = j;
                textBox1.SelectionLength = strEnd.Length;
                if (textBox1.SelectedText == strEnd)
                {

                    endPos = j+strEnd.Length;
                    endPosBetween = j;
                    break;


                }
            }
            
            //text founded with start and end tags
            /*
            textBox1.SelectionStart = startPos;
            textBox1.SelectionLength = endPos - startPos;

            selectionText = textBox1.SelectedText;

            textBox2.AppendText(Environment.NewLine);
            textBox2.AppendText(selectionText);
            textBox2.AppendText(Environment.NewLine);
            */


            //text between start and end tags
            textBox1.SelectionStart = startPosBetween;
            textBox1.SelectionLength = endPosBetween - startPosBetween;

            selectionTextBetween = textBox1.SelectedText;
            
            textBox2.AppendText(Environment.NewLine);
            textBox2.AppendText(selectionTextBetween);
            textBox2.AppendText(Environment.NewLine);

            Text = selectionTextBetween;
        } 


           
        }

    
    }

Comentarii

Postări populare de pe acest blog

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…