Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CONVERSIONS D'ADRESSES EN LIEN HTML


Information sur la source

Catégorie :Texte Niveau : Débutant Date de création : 30/07/2003 Date de mise à jour : 31/07/2003 04:38:34 Vu : 2 829

Note :
Aucune note

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


Description

Bon ben, le texte veut tout dire, cette petite fonction permet de modifier une string par exemple 'cyrille2@free.fr http://www.visiomaster.net/' en '<a href="mailto:cyrille2@free.fr">cyrille2@free.fr</a> <a href="http://www.visiomaster.net/">http://www.visiomaster.net/</a>". Pour l'appeler il suffit de faire

mastring := HandleProtocols(mastring,['http://','ftp://']); par exemple!  
 

Source

  • procedure ExplodeConcat(Source, Splitter : String; ConcatStart : Integer ; var SList : TStringDynArray);
  • var SplitPos : integer;
  • SLenght : Integer;
  • begin
  • SetLength(SList,1);
  • SLenght := 1;
  • SList[0] := Source;
  • repeat
  • SplitPos := posfull(Splitter,Source,True)-1;
  • Inc(SLenght);
  • SetLength(Slist,SLenght);
  • SList[SLenght-1] := Copy(Source,1,SplitPos);
  • Delete(Source,1,SplitPos+1);
  • until (Source = '') or (SLenght = ConcatStart);
  • if ConcatStart = SLenght Then
  • begin
  • SetLength(SList,ConcatStart+1);
  • SList[ConcatStart] := Source;
  • end
  • else
  • if ConcatStart > SLenght Then
  • begin
  • SetLength(SList,ConcatStart);
  • For SLenght := SLenght+1 to ConcatStart-1 Do
  • SList[SLenght] := '';
  • end;
  • end;
  • function HandleProtocols(Mess : String; protocols: array of string) : String;
  • var Strings : TStringDynArray;
  • I, J : integer;
  • Pos1 :integer;
  • begin
  • ExplodeConcat(Mess,' ',-1,Strings);
  • For I := 1 To length(Strings)-1 Do // mess complet
  • begin
  • Pos1 := pos('@',Strings[I]);
  • if not (Pos1 = 0) and not (PosFrom('.',strings[I],Pos1) = 0) Then
  • Strings[I] := '<a href="mailto:'+StringReplace(Strings[I],'"','',[rfReplaceAll])+'">'+Strings[I]+'</a>'
  • else
  • For J := 0 to Length(protocols)-1 Do
  • begin
  • Pos1 := Pos(protocols[J],Strings[I]);
  • if Pos1 = 1 Then
  • begin
  • Strings[I] := '<a href="'+StringReplace(Strings[I],'"','',[rfReplaceAll])+'">'+Strings[I]+'</a>';
  • Break;
  • end;
  • end;
  • Result := Result+' '+strings[I];
  • end;
  • SetLength(Strings,0);
  • end;
procedure ExplodeConcat(Source, Splitter : String; ConcatStart : Integer ; var SList : TStringDynArray);
var SplitPos : integer;
    SLenght : Integer;
begin
    SetLength(SList,1);
    SLenght := 1;

    SList[0] := Source;

    repeat
        SplitPos := posfull(Splitter,Source,True)-1;

        Inc(SLenght);
        SetLength(Slist,SLenght);

        SList[SLenght-1] := Copy(Source,1,SplitPos);
        Delete(Source,1,SplitPos+1);
    until (Source = '') or (SLenght = ConcatStart);

    if ConcatStart = SLenght Then
    begin
        SetLength(SList,ConcatStart+1);
        SList[ConcatStart] := Source;
    end
    else
        if ConcatStart > SLenght Then
        begin
            SetLength(SList,ConcatStart);

            For SLenght := SLenght+1 to ConcatStart-1 Do
                SList[SLenght] := '';
        end;
end;


function HandleProtocols(Mess : String; protocols: array of string) : String;
var Strings : TStringDynArray;
    I, J : integer;
    Pos1 :integer;
begin
    ExplodeConcat(Mess,' ',-1,Strings);

    For I := 1 To length(Strings)-1 Do // mess complet
    begin
        Pos1 := pos('@',Strings[I]);

        if not (Pos1 = 0) and not (PosFrom('.',strings[I],Pos1) = 0) Then
            Strings[I] := '<a href="mailto:'+StringReplace(Strings[I],'"','',[rfReplaceAll])+'">'+Strings[I]+'</a>'
        else
            For J := 0 to Length(protocols)-1 Do
            begin
                Pos1 := Pos(protocols[J],Strings[I]);

                if Pos1 = 1 Then
                begin
                    Strings[I] := '<a href="'+StringReplace(Strings[I],'"','',[rfReplaceAll])+'">'+Strings[I]+'</a>';
                    Break;
                end;
            end;

        Result := Result+' '+strings[I];
    end;

    SetLength(Strings,0);
end;  

Conclusion

Bon conding ^^  
 

Commentaires et avis

Aucun commentaire pour le moment.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,250 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.