Autor Beitrag
Maniacmd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

Windows XP
Delphi 7 Personal
BeitragVerfasst: Mo 01.01.07 20:32 
hi
wie kann ich von einem string die ersten 3 zeilen löschen das ich zum beispiel
aus 1234567 4567 mache?
mfg
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 01.01.07 20:39 
versuchs mal mit delete (z. b. delete(s, 1, 3))
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Mo 01.01.07 21:00 
mir würd da noch ne schleifen lösung einfallen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
stringA:string;

begin
for I:=1 to length(stringA) do
 begin
 if I+3 <length(stringA) then
 stringA[I]:=stringA[I+3]
 else
 stringA[I]:='';
 end;

end;


kp obs funzt ich denke aber schon

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 01.01.07 21:09 
user profile iconJann1k hat folgendes geschrieben:
mir würd da noch ne schleifen lösung einfallen

var
stringA:string;

begin
for I:=1 to length(stringA) do
begin
if I+3 <length(stringA) then
stringA[I]:=stringA[I+3]
else
stringA[I]:='';
end;

end;

kp obs funzt ich denke aber schon

Warum über Montevideo nach Rom? (Spruch meines Mathelehrers :mrgreen: , wenn etwas komplizierter gemacht wird, als es ist)
Mit Delete (s,1,3) schneidest du aus dem String s ab dem ersten Buchstaben drei weg.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 01.01.07 21:12 
user profile iconJann1k hat folgendes geschrieben:
mir würd da noch ne schleifen lösung einfallen

var
stringA:string;

begin
for I:=1 to length(stringA) do
begin
if I+3 <length(stringA) then
stringA[I]:=stringA[I+3]
else
stringA[I]:='';
end;

end;

kp obs funzt ich denke aber schon
1. Was hat das für einen Sinn das so zu machen? Das ist doch langsamer als mit Delete und macht dasselbe (mal von der Tatsache abgesehen, dass dein Code so nicht ganz funktioniert...)
2. Wie wärs mit Delphi-Formatierung?

Jedenfalls wäre dein Code so korrekt: Aber das schreibe ich nur zur der Vollständigkeit halber! Nicht weil ich die Verwendung empfehle!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  stringA: string;
  i: Integer;
begin
  for i := 1 to Length(stringA) do
  begin
    if I+3 <length(stringA) then
      stringA[I]:=stringA[I+3]
    else
      stringA[I]:='';
  end;
  SetLength(stringA, Length(stringA) - 3);
end;

Oder besser so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  stringA: string;
  i: Integer;
begin
  for i := 1 to Length(stringA) - 3 do
    stringA[i] := stringA[i + 3];
  SetLength(stringA, Length(stringA) - 3);
end;
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Mo 01.01.07 21:16 
okay, hätte echt nochmal übern quelltext drübergucken sollen
Maniacmd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

Windows XP
Delphi 7 Personal
BeitragVerfasst: Mo 01.01.07 21:19 
ok danke
Delete (s,1,3) das s steht für den string den ich verkürzen möchte oder?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 01.01.07 21:20 
Richtig! Und es muss eine echte String-Variable sein, also var s: String; und nicht sowas wie Memo1.Text, weil nur eine solche Variable von der Delete-Funktion verändert werden kann.
Maniacmd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

Windows XP
Delphi 7 Personal
BeitragVerfasst: Mo 01.01.07 21:47 
gut aber ich könnte doch eigentlich eine variable deklarieren und dann schreiben
ausblenden Delphi-Quelltext
1:
2:
var mytext:string;
mytext:=label1.caption;


und dann

ausblenden Delphi-Quelltext
1:
Delete (mytext,1,3)					


oder?

Moderiert von user profile iconAXMD: Delphi-Tags hinzugefügt
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 01.01.07 21:52 
Hallo Maniacmd!

Verwende bitte Delphi-Tags, wenn du Code postest. Genaueres dazu findest du in der Hilfe.

AXMD
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 01.01.07 21:53 
Ja, das geht, aber warum probierst du es nicht einfach aus wenn du soweit bist?
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 01.01.07 21:53 
Ja.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Ransom
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Mo 01.01.07 21:53 
Ja, kannst du.
Allerdings solltest du dann auch noch label1.caption:=mytext;
dahinterschreiben, damit man den geänderten Text auch im Label sieht ;)
Maniacmd Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

Windows XP
Delphi 7 Personal
BeitragVerfasst: Mo 01.01.07 21:54 
alles klar