AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Von einem String vorne und hinten alle Leerzeichen entfernen
Thema durchsuchen
Ansicht
Themen-Optionen

Von einem String vorne und hinten alle Leerzeichen entfernen

Ein Thema von Dragon27 · begonnen am 10. Okt 2006 · letzter Beitrag vom 10. Okt 2006
Antwort Antwort
Seite 1 von 2  1 2      
Dragon27

Registriert seit: 20. Nov 2003
Ort: Aßling
543 Beiträge
 
Delphi XE6 Enterprise
 
#1

Von einem String vorne und hinten alle Leerzeichen entfernen

  Alt 10. Okt 2006, 09:26
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!
Delphi is ......... DELPHI!!
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 09:28
mit der Funktion trim

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat
Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#3

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 09:31
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.
Rob
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#4

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 09:37
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
Klaus
  Mit Zitat antworten Zitat
Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#5

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 09:45
Hello Klaus,

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

Greetings,

Delphi-Lover.
Rob
  Mit Zitat antworten Zitat
Benutzerbild von glkgereon
glkgereon

Registriert seit: 16. Mär 2004
2.287 Beiträge
 
#6

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 09:48
Zitat von Delphi-Lover:
Hello Klaus,

Stimmt , but to keep care of the characters in the string was not part of the question
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
»Unlösbare Probleme sind in der Regel schwierig...«
  Mit Zitat antworten Zitat
Benutzerbild von leddl
leddl

Registriert seit: 13. Okt 2003
Ort: Künzelsau
1.613 Beiträge
 
Delphi 2006 Professional
 
#7

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 09:49
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
Axel Sefranek
A programmer started to cuss, cause getting to sleep was a fuss.
As he lay there in bed, looping round in his head
was: while(!asleep()) ++sheep;
  Mit Zitat antworten Zitat
xaromz

Registriert seit: 18. Mär 2005
1.682 Beiträge
 
Delphi 2006 Enterprise
 
#8

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 09:50
Hello,
Zitat von Delphi-Lover:
but to keep care of the characters in the string was not part of the question
Preserving space characters inside the string was part of the question, which your code clearly doesn't.

Greets
xaromz
I am a leaf on the wind - watch how I soar
  Mit Zitat antworten Zitat
Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#9

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 10:00
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. Could not believe it was about space characters what indeed can be solved by the trim function.

Greets,

Delphi-Lover.
Rob
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#10

Re: Von einem String vorne und hinten alle Leerzeichen entfe

  Alt 10. Okt 2006, 10:02
Dragon27 just uses then uderscores to visualize space characters as he wrote in this question (spaces = Leerzeichen)
Markus Kinzler
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:49 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz