Mega Code Archive

 
Categories / Delphi / Strings
 

10 most used String functions & procedures

Title: 10 most used String functions & procedures Question: Don't know what can you really do with a string? Then check this article. Answer: Here is an example of the 10 most used by me functions and procedures: procedure TForm1.Button1Click(Sender: TObject); var S: String; begin { 1 } S := Copy('Delphi Rulezz', 5, 6); { Reads the text } ShowMessage(S); { 2 } S := Concat('1 ',' Two, ','3'); { Connects the text } ShowMessage(S); { 3 } ShowMessage('Length: '+IntToStr(Length('Good'))); { Shows the length of the string in numbers [integer] } { 4 } S := 'The Example'; {Deletes the text } Delete(S, 8, 7); ShowMessage(S); { 5 } S := 'Ralph is a dog'; Insert('good ', S, 12); { Inserts the text } ShowMessage(S); { 6 } S := 'Delphi'; ShowMessage(UpperCase(S)); { Converts the text to upper case } { 7 } S := 'Delphi'; ShowMessage(LowerCase(S)); { Converts the text to lower case } { 8 } S := 'Delphi'; ShowMessage('''P'' in ''Delphi'' is:'+IntToStr(Pos('p',S))+'th'); { Gets the position of the string in the string } { 9 } S := 'a1, a2, a3, a4, a5.'; ShowMessage('a change to b: ' + StringReplace(S, 'a', 'b', [rfReplaceAll])); { Changes the text from one to another } { 10 } S := 'This text:goes lower.'; S := WrapText(S, #13#10, [':'], 12); ShowMessage(S); { Moves the text lower } end; That's it.