begin process at 2010 02 10 00:07:34
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Texte

 > TRAITEMENT DE CHAÎNE DE CARACTÈRES

TRAITEMENT DE CHAÎNE DE CARACTÈRES


 Information sur la source

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

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Texte Niveau :Débutant Date de création :30/05/2004 Date de mise à jour :31/05/2004 16:55:00 Vu :3 339

Auteur : Blacknight66

Ecrire un message privé
Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

 Description

Je suis en train de developper un logiciel pour ma société, j'ai besoin d'outils, et etant confronté a pas mal de problème, je suis arrivé a passer plus de temps a concevoir des petites fonctions plutot interressante. En voici une qui, j'espère vous servira peut être.

Sa fonction, vous rentrez une chaine, plusieurs infos sont contenue dedans, séparée par un caractère défini par vous meme, ensuite, un exemple et plus concret  je crois, car l'expliquer et trop dur ....


Exemple :

Votre chaine = 'RADEON 7200/9600/9600 Pro/Un Deux Trois 25/36'

le résultat    = RADEON 7200
                     RADEON 9600
                     RADEON 9600 Pro
                     Un Deux Trois 25
                     Un Deux Trois 36

Voila ...

Source

  • function FormatStr(Str : string; Sep : Char; MaxLen : integer): string;
  • var
  • J : integer;
  • IxC : char;
  • CRLF : AnsiString;
  • R,T,F : string;
  • function FindPos(Sep : Char; Txt : string; Max : integer) : integer;
  • var
  • P,I,B : integer;
  • Tmp : string;
  • begin
  • Tmp:= '';
  • Tmp:= Txt;
  • I:= Pos(Sep,Tmp);
  • if (Length(Tmp) > MaxLen) then
  • begin
  • Result:= 0;
  • exit;
  • end;
  • if (I = 0) or (I > Max) then
  • begin
  • Result:= 0;
  • exit;
  • end;
  • P:= 0;
  • B:= 0;
  • repeat
  • I:= Pos(Sep,Tmp);
  • if (I > 0) and (I < Max) then
  • begin
  • P:= P + I;
  • delete(Tmp,1,I);
  • end;
  • Inc(B);
  • until (I = 0) or (I > Max) or (B > Length(Txt));
  • Result:= P;
  • end;
  • procedure ScanStr(Txt : string);
  • const
  • Base : array[1..30] of char = (#32,#33,#34,#35,#36,#37,#38,#40,#41,#42,
  • #44,#45,#46,#47,#58,#59,#60,#61,#62,#64,
  • #91,#92,#93,#94,#95,#96,#123,#124,#125,
  • #126);
  • var
  • X,Y : byte;
  • begin
  • Ixc:= #0;
  • Y:= 0;
  • repeat
  • for X:= 1 to 30 do
  • begin
  • if Base[X] <> Sep then
  • begin
  • Y:= Pos(Base[X],Txt);
  • if Y > 0 then
  • begin
  • IxC:= Txt[Y];
  • exit;
  • end;
  • end;
  • end;
  • until Y = 0;
  • end;
  • procedure ScanIx(Tp,Max : byte);
  • var
  • ISS : byte;
  • TSI : string;
  • begin
  • TSI:= Copy(T,1,Max);
  • ScanStr(TSI);
  • ISS:= FindPos(IxC,TSI,Max);
  • if (ISS > 0) and (ISS < Max) then
  • begin
  • F:= Copy(TSI,1,ISS);
  • if Tp = 2 then
  • begin
  • Delete(T,1,ISS);
  • Dec(J,ISS);
  • end;
  • end;
  • case Tp of
  • 1 : R:= Copy(T,1,J - 1) + CRLF;
  • 2 : R:= R + F + Copy(T,1,J - 1) + CRLF;
  • end;
  • Delete(T,1,J);
  • end;
  • begin
  • CRLF:= #13#10;
  • R:= '';
  • F:= '';
  • T:= Str;
  • J:= Pos(Sep,T);
  • if Length(T) > MaxLen then exit;
  • if J = 0 then
  • begin
  • Result:= T;
  • exit;
  • end;
  • T:= T + Sep;
  • ScanIx(1,J);
  • repeat
  • J:= Pos(Sep,T);
  • if J > 0 then ScanIx(2,J);
  • until J = 0;
  • R:= R + T;
  • Result:= R;
  • end;
function FormatStr(Str : string; Sep : Char; MaxLen : integer): string;
var
   J     : integer;
   IxC   : char;
   CRLF  : AnsiString;
   R,T,F : string;

function FindPos(Sep : Char; Txt : string; Max : integer) : integer;
var
   P,I,B : integer;
   Tmp   : string;

begin
     Tmp:= '';
     Tmp:= Txt;
     I:= Pos(Sep,Tmp);
     if (Length(Tmp) > MaxLen) then
     begin
         Result:= 0;
         exit;
     end;
     if (I = 0) or (I > Max) then
     begin
          Result:= 0;
          exit;
     end;
     P:= 0;
     B:= 0;
     repeat
           I:= Pos(Sep,Tmp);
           if (I > 0) and (I < Max) then
           begin
                P:= P + I;
                delete(Tmp,1,I);
           end;
           Inc(B);
     until (I = 0) or (I > Max) or (B > Length(Txt));
     Result:= P;
end;

procedure ScanStr(Txt : string);
const
     Base : array[1..30] of char = (#32,#33,#34,#35,#36,#37,#38,#40,#41,#42,
                                    #44,#45,#46,#47,#58,#59,#60,#61,#62,#64,
                                    #91,#92,#93,#94,#95,#96,#123,#124,#125,
                                    #126);
var
   X,Y : byte;

begin
     Ixc:= #0;
     Y:= 0;
     repeat
           for X:= 1 to 30 do
           begin
                if Base[X] <> Sep then
                begin
                     Y:= Pos(Base[X],Txt);
                     if Y > 0 then
                     begin
                          IxC:= Txt[Y];
                          exit;
                     end;
                end;
           end;
     until Y = 0;
end;

procedure ScanIx(Tp,Max : byte);
var
   ISS : byte;
   TSI : string;

begin
     TSI:= Copy(T,1,Max);
     ScanStr(TSI);
     ISS:= FindPos(IxC,TSI,Max);
     if (ISS > 0) and (ISS < Max) then
     begin
          F:= Copy(TSI,1,ISS);
          if Tp = 2 then
          begin
               Delete(T,1,ISS);
               Dec(J,ISS);
          end;
     end;
     case Tp of
          1 : R:= Copy(T,1,J - 1) + CRLF;
          2 : R:= R + F + Copy(T,1,J - 1) + CRLF;
     end;
     Delete(T,1,J);
end;

begin
     CRLF:= #13#10;
     R:= '';
     F:= '';
     T:= Str;
     J:= Pos(Sep,T);
     if Length(T) > MaxLen then exit;
     if J = 0 then
     begin
          Result:= T;
          exit;
     end;
     T:= T + Sep;
     ScanIx(1,J);
     repeat
           J:= Pos(Sep,T);
           if J > 0 then ScanIx(2,J);
     until J = 0;
     R:= R + T;
     Result:= R;
end;



 Sources de la même categorie

Source avec Zip COMBINAISONS DE STRINGS par askil2000
Source avec Zip Source avec une capture RECONNAISSANCE DE CARACTÈRES (OCR) par Bacterius
Source avec Zip Source avec une capture NETTOYAGE AUTOMATIQUE DE NOMS DE FICHIERS par John Dogget
DISTANCE DE JARO-WINKLER par PoulpHunter
Source avec Zip BASE DE DONNÉE WIKI par thithony

Commentaires et avis

Commentaire de DRJEROME le 31/05/2004 09:02:40

Tu peux essayer ça aussi :
________________________________
var
s:string;
begin
     s:= 'RADEON 7200/9600/9600 Pro/Un Deux Trois 25/Un Deux Trois 36';
     s:=StringReplace(s,'/',#13#10,[rfReplaceAll]);
     showmessage(s);
________________________________



Au fait, dans "Blacknight66", tu as choisi le 66 pour le département où tu habites ? (je dis ça car je travaille actuellement dans le 66 et j'habite dans le 11

;)   (DrJerome ou JROD ou DorotheeJ)

Commentaire de Blacknight66 le 31/05/2004 09:47:11

Oui c'est vrai, j'y ai pensé mais cette fonction ne me convenait pas.

Pour répondre a ta question, oui j'habites dans le 66.

Commentaire de DRJEROME le 31/05/2004 10:34:46

J'habite Narbonne et travaille à Perpignan (et alentours)

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
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,343 sec (3)

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