Accueil > > > TRAITEMENT DE CHAÎNE DE CARACTÈRES
TRAITEMENT DE CHAÎNE DE CARACTÈRES
Information sur la source
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
Commentaires et avis
|
Derniers Blogs
CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril
Logiciels
Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|