| Home  | Casa  | Hardware  | Networking  | Programmazione  | Software  | Domanda  | Sistemi  |   
Programmazione  
  • C /C + + Programming

  • Computer Programming Languages

  • Delphi Programming

  • Java Programming

  • Programmazione Javascript

  • PHP /MySQL Programmazione

  • Perl Programming

  • Python Programming

  • rubino Programmazione

  • Nozioni di base di Visual Programming
  •  
    Conoscenza Informatica >> Programmazione >> Computer Programming Languages >> Content
    Come convertire HTML in testo in SQL
    Conversione HTML in testo in SQL può essere fatto in modo efficiente con una funzione definita dall'utente . Una funzione definita dall'utente accetta parametri, esegue un'azione, come ad esempio il parsing HTML , e restituisce il risultato sotto forma di valore . La funzione può essere eseguita da qualsiasi istruzione SQL o linguaggio di programmazione esterno . Cose che ti serviranno
    conoscenza intermedia della T - SQL
    autorizzazioni adeguate per creare una funzione di database oggetto
    Show More Istruzioni
    1

    connettersi al database , e . creare un nuovo file SQL
    2

    Inserisci il seguente SQL :

    CREATE FUNCTION [ dbo ] [ CleanHTML ]

    (

    @ . DirtyText varchar ( MAX ) per

    ) per

    RETURNS varchar ( MAX ) per

    AS

    BEGIN

    DECLARE @ BeginPos int

    DECLARE @ endpos int

    DECLARE @ Len int

    - Sostituire l'entità HTML e con il carattere '&' ( questo deve essere fatto prima , come
    < p > - '&' potrebbe essere doppio codificato come '&' ) per

    SET @ BeginPos = CHARINDEX ( '&' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 4 < br

    SET > @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > 0 ) BEGIN

    SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Length , '&' ) per

    SET @ BeginPos = CHARINDEX ( '&' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 4

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - Sostituire il codice HTML entità < con il carattere '<' < br

    > @ BeginPos = CHARINDEX ( '<' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 3

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > 0 ) BEGIN

    SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Length , ' < ; ' ) per

    SET @ BeginPos = CHARINDEX ( ' <' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 3

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - Sostituire il codice HTML entità > con il '>' carattere

    SET @ BeginPos = CHARINDEX ( '>' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 3

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 E @ endpos > 0 e @ Len > 0 ) BEGIN

    SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Lunghezza , '>' ) per

    SET @ BeginPos = CHARINDEX ( '>' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 3

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - Sostituire l'entità HTML e con il carattere '&'

    SET @ BeginPos = CHARINDEX ( '&' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 4

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > 0 ) BEGIN
    < p > SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Length , '&' ) per

    SET @ BeginPos = CHARINDEX ( '&' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 4

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - Sostituire l'entità HTML con il carattere ' ' < br

    > @ BeginPos = CHARINDEX ('' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 5

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > 0 ) BEGIN

    SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Lunghezza , ' ' ) per

    SET @ BeginPos = CHARINDEX (' ' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 5

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - Sostituire i tag con un a capo

    SET @ BeginPos = CHARINDEX ( '' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 3

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > 0 ) BEGIN

    SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Length , CHAR ( 13) + CHAR ( 10) ) per

    SET @ BeginPos = CHARINDEX ( '' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 3

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - sostituire eventuali
    tag con un a capo

    SET @ BeginPos = CHARINDEX ( '
    ' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 4

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > 0 ) BEGIN
    < p > SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Lunghezza , ' CHAR ( 13) + CHAR ( 10) ' ) per

    SET @ BeginPos = CHARINDEX ( '
    ' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 4

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - sostituire i tag
    con un a capo

    SET @ BeginPos = CHARINDEX ( '
    ', @ DirtyText ) per

    SET @ endpos = @ BeginPos + 5

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > 0 ) BEGIN
    < p > SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Lunghezza , ' CHAR ( 13) + CHAR ( 10) ' ) per

    SET @ BeginPos = CHARINDEX ( '
    ' , @ DirtyText ) per

    SET @ endpos = @ BeginPos + 5

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    END

    - rimuovere qualsiasi cosa tra i tag

    SET @ BeginPos = CHARINDEX ( '<' , @ DirtyText ) per

    SET @ endpos = CHARINDEX ( '>' , @ DirtyText , CHARINDEX ( '<' , @ DirtyText ) ) per

    SET @ Len = ( @ endpos - @ BeginPos ) + 1

    WHILE ( @ BeginPos > 0 e @ endpos > 0 e @ Len > , 0 ) BEGIN

    SET @ DirtyText = STUFF ( @ DirtyText , BeginPos @ , @ Length , '' ) per

    SET @ BeginPos = CHARINDEX ( '<' , @ DirtyText ) < br

    SET > @ endpos = CHARINDEX ( '>' , @ DirtyText , CHARINDEX ( '<' , @ DirtyText ) ) per

    SET @ Len = ( @ endpos - @ BeginPos ) + 1 < br >

    END

    RITORNO LTRIM ( RTRIM ( @ DirtyText ) ) per

    END
    3

    Compilare la funzione SQL .
    < br > 4

    Eseguire la funzione , e verificare che restituisce i risultati desiderati . Per esempio :

    Selezionare da dbo.CleanHTML ( ' prova < /BODY > < /HTML > ');

    Previous :

    next :
      Articoli Correlati
    ·Algoritmi di base in Strutture di dati 
    ·Come inviare un allegato e-mail con una linea di comand…
    ·Come convertire ASPX per ASCX 
    ·Come creare un disco da ISO 
    ·Come modificare una pagina Web 
    ·Che lingua sono applicazioni Android scritte in 
    ·Come fare un file LUA per Coordinate 
    ·Come scrivere una variabile in un file di testo in SSIS…
    ·Come utilizzare WPF TextBlock 
    ·Come sottoinsieme di una matrice in MATLAB 
      Articoli in evidenza
    ·Come si fa a inserire dichiarazioni ingresso in MATLAB 
    ·Differenze tra include e require in Ruby 
    ·Java Tutorials Collection 
    ·Come fare un Button in Xcode 
    ·Come ottenere la modalità di una lista in Python 
    ·Tutorial su jQuery e Google Maps 
    ·Come trasformare il vostro codice Java in codice Androi…
    ·Come creare un PDF da un testo con Perl 
    ·Come utilizzare i parametri nelle SSIS 
    ·Come scrivere codice di programmazione che può impedir…
    Copyright © Conoscenza Informatica http://it.wingwit.com