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 !

RIGHT$, LEFT$, MID$, SPLIT, TRIM$,... EN DELPHI


Information sur la source

Catégorie :Divers Niveau : Débutant Date de création : 08/11/2001 Vu / téléchargé: 4 361 / 233

Note :
6 / 10 - par 1 personne
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

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

Description

Voci une unit qui regroupe pas mal de fonctions de manipulation de String,...
fonctions portant le même "nom" que sous vb,...

 

Source

  • unit FctsStr;
  • interface
  • uses
  • Windows,Messages, SysUtils, Classes, Graphics,StdCtrls;
  • function RightTrim(const s:String):String;
  • function LeftTrim(const s:String):String;
  • function InStr(Start: integer; Source: string; SourceToFind: string): integer;
  • function Mid(Source: string; Start: integer; Length: integer): string;
  • function Left(Source: string; Length: integer): string;
  • function Right(Source: string; Lengths: integer): string;
  • function Replace(sData: String; sSubstring: String; sNewsubstring: string): String;
  • function Split(Source, Deli: string; StringList: TStringList): TStringList;
  • function Reverse(Line: string): string;
  • implementation
  • function Reverse(Line: string): string;
  • var i: integer;
  • var a: string;
  • begin
  • For i := 1 To Length(Line) do
  • begin
  • a := Right(Line, i);
  • Result := Result + Left(a, 1);
  • end;
  • end;
  • function Split(Source, Deli: string; StringList: TStringList): TStringList;
  • var
  • EndOfCurrentString: byte;
  • begin
  • repeat
  • EndOfCurrentString := Pos(Deli, Source);
  • if EndOfCurrentString = 0 then
  • StringList.add(Source)
  • else
  • StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
  • Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
  • until EndOfCurrentString = 0;
  • result := StringList;
  • end;
  • function Replace(sData: String; sSubstring: String; sNewsubstring: string): String;
  • var
  • i: integer;
  • lSub: Longint;
  • lData: Longint;
  • begin
  • i := 1;
  • lSub := Length(sSubstring);
  • lData := Length(sData);
  • repeat
  • begin
  • i := InStr(i, sData, sSubstring);
  • If i = 0 Then
  • begin
  • sNewSubString := sData;
  • Exit
  • end
  • Else
  • sData := Copy(sData, 1, i - 1) + sNewsubstring + Copy(sData, i + lSub, lData);
  • i := i + lSub;
  • End;
  • Until i > lData;
  • Replace := sData;
  • end;
  • function Left(Source: string; Length: integer): string;
  • begin
  • Result := copy(Source,1,Length);
  • end;
  • function Right(Source: string; Lengths: integer): string;
  • begin
  • Result := copy(source,Length(Source) - Lengths+1,Lengths+1);
  • end;
  • function Mid(Source: string; Start: integer; Length: integer): string;
  • begin
  • Result := copy(Source,Start,Length);
  • end;
  • function InStr(Start: integer; Source: string; SourceToFind: string): integer;
  • begin
  • Result := pos(SourceToFind,copy(Source,Start,Length(Source) - (Start - 1)));
  • end;
  • function RightTrim(const s:String):String;
  • var
  • i:integer;
  • begin
  • i:=length(s);
  • while (i>0) and (s[i]<=#32) do
  • Dec(i);
  • result:=Copy(s,1,i);
  • end;
  • function LeftTrim(const s:String):String;
  • var
  • i, L:integer;
  • begin
  • L:=length(s);
  • i:=1;
  • while (i<=L) and (s[i]<=#32) do
  • Inc(i);
  • result:=Copy(s,i, MaxInt);
  • end;
  • end.
unit FctsStr;

    interface
    uses
    Windows,Messages, SysUtils, Classes, Graphics,StdCtrls;
    function RightTrim(const s:String):String;
    function LeftTrim(const s:String):String;
    function InStr(Start: integer; Source: string; SourceToFind: string): integer;
    function Mid(Source: string; Start: integer; Length: integer): string;
    function Left(Source: string; Length: integer): string;
    function Right(Source: string; Lengths: integer): string;
    function Replace(sData: String; sSubstring: String; sNewsubstring: string): String;
    function Split(Source, Deli: string; StringList: TStringList): TStringList;
    function Reverse(Line: string): string;

    implementation
    function Reverse(Line: string): string;
    var i: integer;
    var a: string;
    begin
    For i := 1 To Length(Line) do
    begin
    a := Right(Line, i);
    Result := Result + Left(a, 1);
    end;
    end;
    function Split(Source, Deli: string; StringList: TStringList): TStringList;
    var
    EndOfCurrentString: byte;
    begin
    repeat
    EndOfCurrentString := Pos(Deli, Source);
    if EndOfCurrentString = 0 then
    StringList.add(Source)
    else
    StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
    Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
    until EndOfCurrentString = 0;
    result := StringList;
    end;
    function Replace(sData: String; sSubstring: String; sNewsubstring: string): String;
    var
    i: integer;
    lSub: Longint;
    lData: Longint;
    begin
    i := 1;
    lSub := Length(sSubstring);
    lData := Length(sData);
    repeat
    begin
    i := InStr(i, sData, sSubstring);
    If i = 0 Then
    begin
    sNewSubString := sData;
    Exit
    end
    Else
    sData := Copy(sData, 1, i - 1) + sNewsubstring + Copy(sData, i + lSub, lData);
    i := i + lSub;
    End;
    Until i > lData;
    Replace := sData;
    end;
    function Left(Source: string; Length: integer): string;
    begin
    Result := copy(Source,1,Length);
    end;
    function Right(Source: string; Lengths: integer): string;
    begin
    Result := copy(source,Length(Source) - Lengths+1,Lengths+1);
    end;
    function Mid(Source: string; Start: integer; Length: integer): string;
    begin
    Result := copy(Source,Start,Length);
    end;
    function InStr(Start: integer; Source: string; SourceToFind: string): integer;
    begin
    Result := pos(SourceToFind,copy(Source,Start,Length(Source) - (Start - 1)));
    end;
    function RightTrim(const s:String):String;
    var
    i:integer;
    begin
    i:=length(s);
    while (i>0) and (s[i]<=#32) do
    Dec(i);
    result:=Copy(s,1,i);
    end;
    function LeftTrim(const s:String):String;
    var
    i, L:integer;
    begin
    L:=length(s);
    i:=1;
    while (i<=L) and (s[i]<=#32) do
    Inc(i);
    result:=Copy(s,i, MaxInt);
    end;

end.

Conclusion

Ce code n'est pas de moi, mais il peut servir ;-)
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Commentaires et avis

signaler à un administrateur
Commentaire de Ced-2 le 21/12/2001 20:32:36

vb.net puduku...
je l'ai isntallé (2mois), chargé(1hr) et vite fermé !
que du superflu la dedans....

je l'ai pas encore désinstaller mais si delphi me plait ca ne saurait tarder...

signaler à un administrateur
Commentaire de taye78 le 08/12/2002 18:34:36

Jai un pb a utilisé la fonction Split(); si tu pouvais me donner un exemple "complet" de cette derniere stp :)

signaler à un administrateur
Commentaire de taye78 le 10/12/2002 10:03:01

Tu pourrais pas nous faire un exemple de chaque fonction stp ?

signaler à un administrateur
Commentaire de fabiin le 10/12/2002 18:12:40

je n'en vois pas l'utilité,
kel fonction te pose problème ?

signaler à un administrateur
Commentaire de LeDesassembleur le 21/10/2004 14:09:22

J'explose !

J'en ai ras la casquette de ces guerres de langages !
On est tous programmeurs et si certains mettent ce genre d'"outils" c'est qu'il y a certainement un besoin.
Maintenant, qu'un langage soit supérieur à un autre, j'en doute !
Il n'y a pas de langage "noble" ou de langage "poubelle"...
Chacun a son utilité, son domaine de prédilection et son public.
Personnelement, j'adore java mais je pratique également vb et je n'ai pas honte de le dire : j'aime bien vb (ben oui...)
Qu'on se gargarise en catégorisant les utilisateurs d'autres langages comme une sous-classe de sous-programmeur m'ennerve !
Si on arretait de pratiquer le nombrilisme, le monde aurait peut-être enfin un gout sucré plutôt qu'amer.
Fin de la pensée philosophique du jour...

Que chacun programme avec le langage qu'il aime ou qu'il maitrise. Point final.
Les "puduku" ou autres expressions tout droit sorties des cours d'écoles me font bouillir.

Si vous êtes d'accord avec ma vision, merci de le dire, je me sentirai moins seul...

Sans rancunes !
Et bonne programmation à tous

Le Désassembleur (alias Bertrand)

signaler à un administrateur
Commentaire de retaks666 le 08/02/2005 18:14:52

ça marche pas chez moi split, j'ai corrigé de la sorte:
function Split(Source, Deli: string): TStringlist;
    var
    EndOfCurrentString: byte;
    begin
    //result:= TStringList.Create;
    result.Clear;
    repeat
    EndOfCurrentString := Pos(Deli, Source);
    if EndOfCurrentString = 0 then
    result.add(Source)
    else
    result.add(Copy(Source, 1, EndOfCurrentString - 1));
    Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
    until EndOfCurrentString = 0;

    end;

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,452 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é.