// Extract a specified number of strings from the left and right sides: ansileftstr, ansirightstrvar SS, S: ansistring; begin SS: = 'abcdef'; s: = ansileftstr (SS, 2 ); showmessage (s); {AB} s: = ansirightstr (SS, 2); showmessage (s); {FG} end;
// Extract the string of the specified length from the specified position: ansimidstrvar SS, S: ansistring; begin SS: = 'abcdefg'; s: = ansimidstr (SS, 3, 2 ); showmessage (s); {CD} s: = ansimidstr (SS, 3,20); showmessage (s); {cdefg} end;
// Query string: ansicontainsstr, ansicontainstextvar SS, S: ansistring; B: Boolean; begin SS: = 'Hello world'; s: = 'hello'; B: = ansicontainsstr (SS, S); {Case Sensitive} showmessage (booltostr (B); {false} B: = ansicontainstext (SS, S ); {Case Insensitive} showmessage (booltostr (B); {true} end;
// Determine whether a string starts with another string: ansistartsstr, ansistartstextvar SS, S: ansistring; B: Boolean; begin SS: = 'Hello world'; s: = 'hes '; b: = ansistartsstr (S, SS); {Case Sensitive} showmessage (booltostr (B); {false} B: = ansistartstext (S, SS ); {Case Insensitive} showmessage (booltostr (B); {true} end;
// Judge whether a string ends with another string: ansiendsstr, ansiendstextvar SS, S: ansistring; B: Boolean; begin SS: = 'Hello world'; s: = 'orld '; b: = ansiendsstr (S, SS); {Case Sensitive} showmessage (booltostr (B); {false} B: = ansiendstext (S, SS ); {Case Insensitive} showmessage (booltostr (B); {true} end;
// Replacement string: ansireplacestr, ansireplacetextvar SS, strform, strto: ansistring; begin SS: = 'Hello World Hello world'; strform: = 'hello'; strto: = '*'; SS: = ansireplacestr (SS, strform, strto); {Case Sensitive} showmessage (SS); {Hello World Hello world} SS: = ansireplacetext (SS, strform, strto); {Case Insensitive} showmessage (SS); {* World * world} end;
// Determine whether two strings are similar: ansiresemblestextvar B: Boolean; begin B: = ansiresemblestext ('abc', 'apc '); showmessage (booltostr (B )); {true indicates two strings are similar} {What is its basis? I am very interested. In another essay, I will study the topic} end;
// Flip string: ansireversestringvar S: ansistring; begin S: = 'hello'; s: = ansireversestring (s); showmessage (s); {olleh} end;
// Search for string Arrays: ansimatchstr and ansimatchtextvar arr: array [0 .. 3] of string; s: ansistring; B: Boolean; begin arr [0]: = 'aaa'; arr [1]: = 'bbb '; arr [2]: = 'ccc '; arr [3]: = 'ddd'; s: = 'ccc '; B: = ansimatchstr (S, arr ); {Case Sensitive} showmessage (booltostr (B); {false} B: = ansimatchtext (S, arr); {Case Insensitive} showmessage (booltostr (B )); {true} end;
// Locate the string array and return the sub-string location: ansiindexstr, ansiindextextvar arr: array [0 .. 3] of string; s: ansistring; I: integer; begin arr [0]: = 'aaa'; arr [1]: = 'bbb '; arr [2]: = 'ccc '; arr [3]: = 'ddd'; s: = 'ccc '; I: = ansiindexstr (S, arr ); {Case Sensitive} showmessage (inttostr (I); {-1,-1 indicates not found} I: = ansiindextext (S, arr ); {Case Insensitive} showmessage (inttostr (I); {2} end;
// Start with the characters to search for the position of the string: posexvar SS, S: string; I: integer; begin SS: = 'codegear Delphi 2007 '; s: = 'gear '; i: = posex (S, SS, 4); showmessage (inttostr (I); // 5end;