Get First word that contains numbers

后端 未结 5 680
醉梦人生
醉梦人生 2021-01-22 18:58

Anyone can help with how can I find the first full Word that contains numbers? I have an adress, for example:

procedure TForm1.Button4Click(Sender: TObject);
var         


        
5条回答
  •  心在旅途
    2021-01-22 19:25

    Test if a string contains a digit by looping of the string and checking each character. For instance:

    function ContainsDigit(const S: string): Boolean;
    var 
      C: Char;
    begin
      for C in S do
        if (C >= '0') and (C <= '9') then
          exit(True);
      exit(False);
    end;
    

    Or you might prefer to write the if statement using the record helper methods from the System.Character unit.

    uses
      System.Character;
    
    ....
    
    function ContainsDigit(const S: string): Boolean;
    var 
      C: Char;
    begin
      for C in S do
        if C.IsDigit then
          exit(True);
      exit(False);
    end;
    

提交回复
热议问题