AnsiString Funktionen (Trim,Trimleft,Trimright)
-
Ich bin noch am anfang mit dem porggen, aber mein lehrer hat mich auf ansistring fungtionen (trim-funktionen) angesprochen und ich hatte keine ahnung, nun suche ich im ganzen netz, aber habe nicht für mich (anfänger) verständliches gefungen. währe echt cool, wenn mir das so im groben mit ansistring algemein und mit den trim funktionen erklären könntet.
danke
-
die AnsiString Trimfunktionen sind bestimmt von Borland kann das sein?
AnsiString != std::string ( aus dem ANSI/ISO Standard ) ![Edit]Btw ist das hier das falsche Forum![/Edit]
http://www.functionx.com/bcb/topics/strings.htm schrieb:
String Trimming
Trimming a string is an operation that gets rid of leading or ending spaces in a string. To remove any (empty) space on the left side of a string, you can use the AnsiString::TrimLeft() method. Its syntax is:
AnsiString __fastcall TrimLeft() const;
If the original string has space on its left, this function would remove it and return a string that is like the original without the leading space. If the original does not have any leading space, the function would return the same string:
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text = Edit1->Text.TrimLeft(); } //---------------------------------------------------------------------------
Another function used to perform the same operation is the TrimLeft(). Its syntax is:
AnsiString _fastcall TrimLeft(const AnsiString S);
As opposed to the AnsiString::TrimLeft() method, the (global) TrimLeft() function takes one argument which is the string that needs to be left trimmed. The function returns a new string that is the same as the original omitting the leading space (if any exists):
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text = TrimLeft(Edit1->Text); } //---------------------------------------------------------------------------
To remove any space on the right side of a string, you can use the AnsiString::TrimRight() method. Its syntax is:
AnsiString __fastcall TrimRight() const;
If the original string has space on its right, this function would remove it and return the same string without any trailing space. Otherwise, the original string would be returned:
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text = Edit1->Text.TrimRight(); } //---------------------------------------------------------------------------
Another function used to perform the same operation is the TrimRight(). Its syntax is:
AnsiString _fastcall TrimRight(const AnsiString S);
The (global) TrimRight() function requires one argument as the string that needs to be trimmed. The function returns the original string without the trailing space:
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text = TrimRight(Edit1->Text); } //---------------------------------------------------------------------------
Other functions allow you to combine the last two operations into one. You can use the AnsiString::Trim() method to remove spaces on both sides of a string. Its syntax is:
AnsiString __fastcall Trim() const;
Here is an example of using this method:
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text = Edit1->Text.Trim(); } //---------------------------------------------------------------------------
Alternatively, you can use the global Trim() function to perform the same operation. Its syntax is:
AnsiString _fastcall Trim (const AnsiString S);
Here is an example:
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Edit2->Text = Trim(Edit1->Text); } //---------------------------------------------------------------------------
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum Borland C++ Builder (VCL/CLX) verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.