1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

String To Integer

Discussion in 'Delphi Programming' started by saedi_mehdi, Dec 2, 2013.

  1. saedi_mehdi
    Offline

    saedi_mehdi DF Junior

    Clear string from text
    Sample StrClearInteger('4r5e435')=45435


    function StrClearToInteger(Str: String): String;
    var i: integer;
    begin
      Result := Str;
      for i := Length(Result) downto 1 do
          if not (Result in ['0'..'9']) then
            Delete(Result, i, 1);
    end;
     
  2. amir_kh1845
    Offline

    amir_kh1845 DF Member

    Very Good
    I need a function if string is integer or no?
     
  3. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Code:
    function TForm1.IsNumeric(s: string): boolean;
    var i : integer;
    var test:string;
    begin
     for i:= 0 to 47 do
       begin
         if (pos(chr(i),s) > 0) then
           begin
             result := false;
           end;
       end;
    //between  48-57 is numeric 0-9
     for i := 58 to 255 do
       begin
         if (pos(chr(i),s)>0) then
           begin
              result := false;
           end
    
    
     end;
    
    
    end;
     
  4. saedi_mehdi
    Offline

    saedi_mehdi DF Junior

    Thank [r3n4m3]
     
  5. saedi_mehdi
    Offline

    saedi_mehdi DF Junior

    other way

    function StrIsInteger(Str: String): Boolean;
    begin
      result:= not (StrToIntDef(Str, -2147483647)=-2147483647);
    end;
     
  6. wozengcong
    Offline

    wozengcong Guest

  7. drakeblood2
    Offline

    drakeblood2 Guest

    good

     
     
  8. cyb0r
    Offline

    cyb0r DF Member

    Good code snippet
     
  9. nnlscxlm
    Offline

    nnlscxlm DF Member

    Try something like this:

    function IsStrNumeric(const S: string): Boolean;
    begin
      Result := False;
      if S = '' then
        Exit;
      for I := 1 to Length(S) do
      // or, if you need this for both 1-based and 0-based strings (mobile platforms), you could use:
      // for I := Low(S) to High(S)
        if not (S in ['0'..'9']) then
          Exit;
      Result := True;
    end;


     

     


     


     


     
    [hr]
    Or, if you want to be more strict and refuse strings with leading zeros (for example, accept '42' but not '042'):

    function IsStrNumeric(const S: string): Boolean;
    begin
      Result := False;
      if (S = '') or (S[Low(S)] = '0') then
        Exit;
      for I := Low(S) to High(S)
        if not (S in ['0'..'9']) then
          Exit;
      Result := True;
    end;

     
     
  10. vallemanden
    Offline

    vallemanden DF Junior

    great post mate
     
  11. hugorn
    Offline

    hugorn Guest

    solved
     

Share This Page