<% dim OwnItems, ItemSearch, newEspace, ItemCount, MaxItem, ItemPos, LastPos, PreNewItems, NewItems OwnItems = "BBFFFFBBAAFFAAAAFFBBBBAAFFAA" ItemSearch = "AA" newEspace = "FF" ItemCount = 0 MaxItem = 3 ItemPos = 0 LastPos = 0 PreNewItems = "" NewItems = "" int Sucess Sucess = 0 for i=1 to MaxItem if i=1 then ItemPos = InStr(ItemPos+1, OwnItems, ItemSearch) end if if ItemPos > 0 then ItemPos = InStr(ItemPos+1, OwnItems, ItemSearch) ItemCount = ItemCount+1 if i=MaxItem then LastPos = ItemPos end if end if next if ItemCount >= MaxItem then PreNewItems = Replace(Left(OwnItems,LastPos-1+Len(ItemSearch)),ItemSearch,newEspace) NewItems = PreNewItems + Right(OwnItems,len(OwnItems) - len(PreNewItems)) Sucess = 1 end if if Sucess <> 1 then ShowBool = "Năo" else ShowBool = "Sim" response.write("OwnItems = " & OwnItems & "<br>") response.write("ItemSearch = " & ItemSearch & "<br>") response.write("newEspace = " & newEspace & "<p>") response.write("ItemCount = " & ItemCount & "<br>") response.write("LastPos = " & LastPos & "<p>") response.write("PreNewItems = " & PreNewItems & "<br>") response.write("NewItems = " & NewItems & "<p>") response.write("ShowOwnItems = " & Replace(Replace(Replace(OwnItems,"FF","Nada, "),"AA","<b>Ameixa</b>, "),"BB","Bola, ") & "<br>") response.write("ShowNewItems = " & Replace(Replace(Replace(NewItems,"FF","Nada, "),"AA","<b>Ameixa</b>, "),"BB","Bola, ") & "<p>") response.write("Funçăo: O Código consiste em substituir as " & MaxItem & " primeira(s) string(s) :: <b>" & ItemSearch & "</b> :: por :: <b>" & newEspace & "</b><br>") response.write("OwnItems possui " & MaxItem & " string(s) denominadas :: " & ItemSearch & " :: ? <b>" & ShowBool & "</b>") %>
Os Resultados foram:
OwnItems = BBFFFFBBAAFFAAAAFFBBBBAAFFAA ItemSearch = AA newEspace = FF ItemCount = 3 LastPos = 15 PreNewItems = BBFFFFBBFFFFFFFF NewItems = BBFFFFBBFFFFFFFFFFBBBBAAFFAA ShowOwnItems = Bola, Nada, Nada, Bola, Ameixa, Nada, Ameixa, Ameixa, Nada, Bola, Bola, Ameixa, Nada, Ameixa, ShowNewItems = Bola, Nada, Nada, Bola, Nada, Nada, Nada, Nada, Nada, Bola, Bola, Ameixa, Nada, Ameixa, Funçăo: O Código consiste em substituir as 3 primeira(s) string(s) :: AA :: por :: FF OwnItems possui 3 string(s) denominadas :: AA :: ? Sim
No caso, eu estipulei 3, ou seja, ele substitui as 3 primeiras strings XX por YY, o resto permanece.
T+ e vlw gente.