begin process at 2010 03 16 21:41:28
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

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

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


 Information sur la source

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

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Divers Niveau :Débutant Date de création :08/11/2001 Vu / téléchargé :4 753 / 242

Auteur : fabiin

Ecrire un message privé
Site perso
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

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip CAPTUER LE SON SORTANT ET L'ENREGISTRER DANS UN FICHIER WAV
CALCUL D'UNE MOYENNE
CHANGER LA DURÉE D'AFFICHAGE DES BULLES D'AIDES (HINT)
Source avec Zip Source avec une capture ASCII-T : PETIT SOFT D'ASCII ART.
CHANGER CONTRASTE / LUMINOSIT&#201; (L'ALGORITHME)

 Sources de la même categorie

Source avec Zip Source avec une capture LOGICIEL DE DIAGNOSTIC AUTOMOBILE KWP2000 par Oniria
Source avec Zip Source avec une capture RÉGLE TRANSPARENTE POUR MESURER UN OBJET ECRAN par dubois77
Source avec Zip Source avec une capture LE BOOK DU PAUVRE par dubois77
Source avec Zip Source avec une capture CAHIER 90 PAGES par dubois77
Source avec Zip Source avec une capture TABLEAU DE BOUTONS DYNAMIQUES (AGENDA) par dubois77

Commentaires et avis

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...

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 :)

Commentaire de taye78 le 10/12/2002 10:03:01

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

Commentaire de fabiin le 10/12/2002 18:12:40

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

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)

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...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

Photothèque

 
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

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,499 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales