String functions in Delphi (6)-ANSI string functions in strutils

Source: Internet
Author: User
// 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;
  
   
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.