Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    RegExp per correzione attributo (o altro metodo)

    salve.
    Dovrei cercare e correggere nel testo html che sto per restituire nella pagina alcuni attributi e verificarne se il valore dell'attributo è racchiuso fa " ".

    Esempio :
    Errato : <.... color=#ff0000 >
    Corretto : <.... color="#ff0000" >

    quindi dovrei cercare tutto quello fra color= e [ ] (intendo "spazio")
    e ed effettuare la correzione.

    Ho già asviluppato una funzioen che fa ciò ma su pagine pesanti inpiega tempo.

    Mia funzione :
    ------------------------------------------------
    codice:
    Testo= contenuto pagina
    
    Testo=W3C_Parser_Attribute_Apici(Testo," color=","<F")
    
    
    Function W3C_Parser_Attribute_Apici(Testo,Attributo_parser,TAG)
    Dim Ind_Conta
    Dim Chiave
    Dim Chiave1
    Dim Chiave2
    Dim Inizio
    Dim Fine
    Dim Inizio1
    Dim Fine3
    Dim Fine1
    Dim Fine2
    Dim Ind
    Dim Testo_Temp
    Dim Vettore_testo(100000)
    Dim Index_vettore
    Dim Testo_Split
    Dim Testo_Splittato
    	if false
    		Ind=1
    		Ind_Conta=0
    		Chiave=""
    		do
    			inizio=instr(Ind,Testo,TAG,1)
    			'SDEBUG("inizio=" & inizio)
    			if inizio>0 then
    				fine=instr(inizio,Testo,">")
    				if fine>inizio then
    					Chiave=mid(Testo,inizio,fine-inizio+1)
    					if instr(1,Chiave,Attributo_parser,1)>0 then
    						inizio1=instr(1,Chiave,Attributo_parser,1)+len(Attributo_parser)
    						fine1=instr(inizio1,Chiave,">",1)-1
    						fine2=instr(inizio1,Chiave," ",1)-1
    						if fine1<=0 then
    							fine1=1000000
    						end if
    						if fine2<=0 then
    							Fine2=1000000
    						end if
    						if fine1<Fine2 then
    							Fine3=Fine1
    						else
    							Fine3=Fine2
    						end if
    						IF fine3-inizio1+1>0 THEN
    							Chiave1=mid(Chiave,inizio1,fine3-inizio1+1)
    							If left(trim(Chiave1),1)<>"""" and right(trim(Chiave1),1)<>"""" then
    								Chiave1="""" & trim(Chiave1) & """ "
    								Chiave=left(Chiave,inizio1-1) & Chiave1 & right(Chiave,len(Chiave)-fine3)
    							end if
    						END IF
    					end if
    					Testo=left(Testo,inizio-1) & Chiave & right(Testo,len(Testo)-fine-len(">")+1)
    				end if
    			else
    				exit do
    			end if
    			Ind=inizio+1
    			Ind_Conta=Ind_Conta+1
    		loop
    	else
    		Testo_Splittato=split(testo,TAG)
    		Index_vettore=0
    		Ind_Conta=0
    		for each Testo_Split in Testo_Splittato
    			Ind=1
    			Chiave=""
    			if Ind_Conta>0 then
    				Testo_Temp=TAG & Testo_Split
    				do
    					inizio=instr(Ind,Testo_Temp,TAG,1)
    					if inizio>0 then
    						fine=instr(inizio,Testo_Temp,">")
    						if fine>inizio then
    							Chiave=mid(Testo_Temp,inizio,fine-inizio+1)
    							if instr(1,Chiave,Attributo_parser,1)>0 then
    								inizio1=instr(1,Chiave,Attributo_parser,1)+len(Attributo_parser)
    								fine1=instr(inizio1,Chiave,">",1)-1
    								fine2=instr(inizio1,Chiave," ",1)-1
    								if fine1<=0 then
    									fine1=1000000
    								end if
    								if fine2<=0 then
    									Fine2=1000000
    								end if
    								if fine1<Fine2 then
    									Fine3=Fine1
    								else
    									Fine3=Fine2
    								end if
    								IF fine3-inizio1+1>0 THEN
    									Chiave1=mid(Chiave,inizio1,fine3-inizio1+1)
    									If left(trim(Chiave1),1)<>"""" and right(trim(Chiave1),1)<>"""" then
    										Chiave1="""" & trim(Chiave1) & """ "
    										Chiave=left(Chiave,inizio1-1) & Chiave1 & right(Chiave,len(Chiave)-fine3)
    									end if
    								END IF
    							end if
    							Testo_Temp=left(Testo_Temp,inizio-1) & Chiave & right(Testo_Temp,len(Testo_Temp)-fine-len(">")+1)
    						end if
    					else
    						exit do
    					end if
    					Ind=inizio+1
    					Ind_Conta=Ind_Conta+1
    				loop
    			else
    				Ind_Conta=Ind_Conta+1
    				Testo_Temp=Testo_Split
    			end if
    			Vettore_testo(Index_vettore)=Testo_Temp
    			Index_vettore=Index_vettore+1
    		next
    		Testo=""
    		for ind=0 to Index_vettore-1
    			Testo=Testo & Vettore_testo(ind)
    		next
    	end if
    	W3C_Parser_Attribute_Apici=testo
    end function
    Scusatemi in anticipo per gli ORRORI di ortografica, ma sono analfabeta
    Electronic parts catalog
    Gestione cataloghi ricambio IPC
    Documentazione tecnica & manuali

  2. #2
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    Ciao CiodoF,

    ho appena risposto ad un altro tuo post
    se ho ben capito vuoi fare una funzione che trova e corregge determinati attributi non racchiusi dalle virgolette
    dimmi se è così
    codice:
    Function W3C_Parser_Attribute_Apici(html,attributo)
      set re = Server.CreateObject("VBScript.RegExp")
      re.Pattern="(<[^\n\r\v>]*" & attributo & "=)([^ >]+)([^\n\r\v>]*?>)"
      re.IgnoreCase=true
      re.Multiline=true
      re.Global=true
      W3C_Parser_Attribute_Apici = re.Replace(html,"$1""$2""$3")
    End Function

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.