Sunteți pe pagina 1din 8

# Siruridecaracterestring

Unsirdecaracterereprezintaosuccesiunedecaracterecuprinsaintre
literemici;
literemari;
cifre;
delimitatori(.,;);
caracterespeciale(#@);
maximeasirului,fienu.
1.varnume:string[25];2.varnume:string;
nume:string[nr];1<=nr<=255;
decaractere,atuncicompilatorulvaalocaunnumarnrdecaracterepentruaceasta
variabila.
Unuisirisepoateasocialovaloareprindouamodalitati:
!!!Observatie!!!
Dacavaloareaceiseatribuieunuisirdecaracteredepasestelungimeamaximaa
egalaculungimeamaximaasa.
Exemple:
a)s:string[3];s:=abcde=>s=abc;
b)s:string;s:=abcde=>s=abcde;
c)s=stringuldelungime0;
d)s=sirdecaracteredelungime1.

Operatiipesiruridecaractere
Serealizeazafolosindoperatorul+.
s:string;
s:=ab++cde;
s=abcde
realizeazafolosindoperatoriirelationali:=,<,<=,>,>=,<>.
caractere.
3)Parcurgereaunuisirdecaractere
length(sir)returneazalungimeasiruluispecificat.
sir:string;
length()=0sirulvid.
s:string;
s[i]caracteruldepepozitiai;
fori:=1tolength(s)do
<prelucreazas[i]>;
!!!Observatii!!!
CA(mare)+32=CA(mic);CAcodulAsci;
2)ord,chrdouafunctiipredefinitespecificecaracterelor;
ORD(uncharacter)=codulAscialcaracterului;
CHR(unnumar)=caracterulcorespunzatorcoduluiAsci.

Functiipredefinitepestringuri
1)POS(sir1,sir2);
2)COPY(sir,poz,nr);
3)LENGTH(sir);
4)CONCAT(c1,c2,,cn);
inceputinsirul2dacaexistasau0dacasirul1nuseaflainsirul2.
2)FunctiaCOPYextrageunsubsiralsiruluispecificat,incepanddinpozitiapozcu
unnumarnrdecaractere.
3)FunctiaLENGTHreturneazalungimeaunuisirdecaractere.

4)FunctiaCONCATlipestemaimultesiruric1,c2,,cn.
!!!Observatii!!!
1)Dacapozestemaimaredecatlength(sir)atuncisirulrezultatvafisirulvid.
2)Dacanrestemaimaredecatlength(sir)poz+1atuncisubsirulobtinutvacontine
numailength(sir)poz+1caractere.
|||
1pozlength(sir)
||
Length(sir)poz+1

Proceduripredefiniteinstringuri
1)DELETE(sir,poz,nr)
Stergedinsirunsirincepandcupozitiapozunnumarnrdecaractere.
!!!Observatie!!!
1)Dacapoz>length(sir)atuncinusestergenimic.
2)Dacanr>length(sir)poz+1,atuncisevorstergelength(sir)poz+1caractere.
Exemple
S=casa;
1)delete(S,2,2)>S=ca;
2)delete(S,7,3)>S=casa;
3)delete(S,3,7)>S=ca.
2)INSERT(subsir,sir,poz)
Insereazasubsiruldatinsirulsirincepanddinpozitiapoz.
!!!Observatii!!!
1)Dacapozitiaestemaimaredecatlength(sir),atuncisubsirulseinsereazala
sfarsitulsirului.
subsir=rr;sir=casa;
insert(subsir,sir,30)>sir=casarr;
insert(subsir,sir,2)>sir=crrasa.
(trunk(int))characterdedupalungime.
sir=casa;subsir=rr;sir:string[4];
insert(subsir,sir,2)>sir=crra.
3)STR(numar,sir)
Transformavariabilanumarintrunsirdecaractere.

12>12.
4)VAL(sir,numar,eroare)
Incearcasatransformesiruldecaracteresirintrunnumarreal.Dacareuseste
atunciparametruleroarevaaveavaloarea0,dacanureusestevaloarea
Val(12.3,numar,eroare)>eroare=0
>numar=12.3
Val(12,3,numar,eroare)>eroare=3
>numar=0.

SETDEPROBLME
1)Saseafisezetoateprefixeleunuicuvant.
2)Saseafisezetoatesufixeleunuicuvant.
3)Saseeliminetoatespatiiledintruntext.
4)Verificatidacauncuvantestepalindrome.5)Afisaticatevocalecontineuntext.
6)Sedauntextincarecuvintelesuntseparateprinspatii.Saseafisezepecateun
randcuvinteletextului.
Programproblema_1;
Varcuv:string;
n,i:integer;
Begin
write(Cuvantuleste:);
n:=length(cuv);
fori:=1tondo
writeln(copy(cuv,1,i);
END.

Programproblema_2;
Varcuv:string;
n,i:integer;
Begin
write(Cuvantuleste:);

n:=length(cuv);
fori:=ndownto1do
writeln(copy(cuv,i,n);
END.

Programproblema_3;
Varcuv:string
i,n:integer;
Begin
write(Cuvantuleste:);
n:=length(cuv);
fori:=1tondo
ifcuv[i]=thenbegin
delete(cuv,i,1);
n:=n1;
end;
fori:=1tondo
write(cuv[i]);
END.

Programproblema_4;
Varcuv:string;
i,n:integer;
OK:Boolean;
Begin
write(Cuvantuleste:);
n:=length(cuv);
OK:=true;
fori:=1tondiv2do
ifcuv[i]<>cuv[ni+1]thenOK:=false;
ifOKthenwriteln(Cuvantulestepalindrom)
elsewriteln(Cuvantulnuestepalindrom);
END>

Programproblema_5;
Vartext:string;
i,n,nr:integer;
Begin
write(Textuleste:);
n:=length(text);
nr:=0;
fori:=1tondo
if(text[i]in[A,E,I,O,U])or(text[i]in[a,e,i,o,u])theninc(nr);
writeln(sunt,nr,vocale);
END.

Programproblema_6;
Vart:string;
n,i:integer;
cuv:string;
Begin
Write(Datitextul:);
N:=length(t);
I:=1;
Whilei<=ndo
Begin
While(t[i]in[,,,.,?,!,:,;])and(i<=n)do
Inc(i);
Cuv:=;
Whilenot(t[i]in[,,,.,?,!,:,;])and(i<=n)do
Begin
Cuv:=cuv+t[i];
Inc(i);
End;
Writeln(cuv);
End;
End.

Fiiere
Unfiieresteostructurdedatecucomponentenumitenregistraricepotavea
dimensiunifixesauvariabile,inceldealdoileatrebuindsaexistenite
marcatoricaresledelimiteze.

dupaaccesullacomponente:

acesteaaufostcitite;
fiierecuaccesdirectincareaccesullacomponentesefacenmoddirect,fara
aseinecontdeordineaintroduceriilor;
dupconinutulfiierelor:
fiieretext,datelefiindconsideratecaracterescrisesecvenial,uneledup
altele,pelinii,asemntormoduluinaturaldescriere;
fiierebinare,cepotconinedatedetipuridiferite,nacestcazfiecare
componentesteconsiderat1octet ;

Operaiicufiieretext

Unfiiertextesteunfiieralecruicomponentesuntcaracterescrise
secvenialpelinii.Pentruaputealucracufiieretexttrebuiecantrunprogram
Pascalsavemdefinitovariabilcaresfaclegturacuunfiiertext
memoratpeunsuportextern(HDD).Oastfeldevariabilsedeclar:
nume_variabil:text;
Exemplu:f:text;
proceduriiassign:
assign(variabil_fiier,'nume_fiier_extern');
Exemplu:assign(f,'fiier.txt');

Alteproceduridelucrucufiieretextsunt:

rewriteesteoprocedurcepermitecreeareaunuifiiertextideschiderea
acestuiapentruscriereanel.Easepoateutilizaastfel:rewrite(f);,undefeste
closeprocedurcuajutorulcreiasenchideunfiiertext

## Meniu subsol

### Obține aplicațiile noastre gratuite

Drepturi de autor © 2022 Scribd Inc.

## Meniu subsol

### Obține aplicațiile noastre gratuite

Drepturi de autor © 2022 Scribd Inc.