Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Von einem String vorne und hinten alle Leerzeichen entfernen (https://www.delphipraxis.net/78721-von-einem-string-vorne-und-hinten-alle-leerzeichen-entfernen.html)

Dragon27 10. Okt 2006 09:26


Von einem String vorne und hinten alle Leerzeichen entfernen
 
Hallo,

ich komme einfach nicht weiter.... Ich würde gerne alle Leerzeichen von einem String vorne und hinten löschen.

Sprich aus dem (_ = Leerzeichen):

Zitat:

____________Hallo Welt! Wie Gehts?_____________
Soll das werden:

Zitat:

Hallo Welt! Wie Gehts?

Könnt Ihr mir helfen wie man soetwas machen kann?

danke!

Klaus01 10. Okt 2006 09:28

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
mit der Funktion trim

Grüße
Klaus

Delphi-Lover 10. Okt 2006 09:31

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Hello,

Try this:

Delphi-Quellcode:
Function DeleteChar(strValue : String; aChar : Char) : String;
Var CharPos : Integer;
Begin
  Repeat
    CharPos:=Pos(aChar,strValue);
    If CharPos<>0 Then Delete(strValue,CharPos,1);
  Until CharPos=0;
  Result:=strValue;
End;
Greets,

Delphi-Lover.

Klaus01 10. Okt 2006 09:37

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Zitat:

Zitat von Delphi-Lover
Hello,

Try this:

Delphi-Quellcode:
Function DeleteChar(strValue : String; aChar : Char) : String;
Var CharPos : Integer;
Begin
  Repeat
    CharPos:=Pos(aChar,strValue);
    If CharPos<>0 Then Delete(strValue,CharPos,1);
  Until CharPos=0;
  Result:=strValue;
End;
Greets,

Delphi-Lover.

Just a remark to your code.
Your Code will also delete characters that are located
in the String and not only the leading and trailing characters.

Regards
Klaus

Delphi-Lover 10. Okt 2006 09:45

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Hello Klaus,

Stimmt :-D , but to keep care of the characters in the string was not part of the question :lol:
The trim function of your answer only deletes "space" characters and the control characters.

Greetings,

Delphi-Lover.

glkgereon 10. Okt 2006 09:48

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Zitat:

Zitat von Delphi-Lover
Hello Klaus,

Stimmt :-D , but to keep care of the characters in the string was not part of the question :lol:
The trim function of your answer only deletes "space" characters and the control characters.

Greetings,

Delphi-Lover.

The question was to eliminate all spaces before and behind the "main string". (and only these!)
that is perfectly done by trim :-)

leddl 10. Okt 2006 09:49

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Zitat:

Zitat von Delphi-Lover
The trim function of your answer only deletes "space" characters and the control characters.

And that was exactly what Dragon27 asked for :zwinker:

xaromz 10. Okt 2006 09:50

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Hello,
Zitat:

Zitat von Delphi-Lover
but to keep care of the characters in the string was not part of the question :lol:

Preserving space characters inside the string was part of the question, which your code clearly doesn't.

Greets
xaromz

Delphi-Lover 10. Okt 2006 10:00

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Hello,

Sorry, I read the question so that the problem was to delete the "_" characters. (underscore). Nothing about space or control chatcharaters. If you see my code it will delete those "_" characters and leave the space characters.
Misunderstood the "_ = Leerzeichen". word. :cyclops: Could not believe it was about space characters what indeed can be solved by the trim function.

Greets,

Delphi-Lover.

mkinzler 10. Okt 2006 10:02

Re: Von einem String vorne und hinten alle Leerzeichen entfe
 
Dragon27 just uses then uderscores to visualize space characters as he wrote in this question (spaces = Leerzeichen)


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:12 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz