Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator 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

    vallemandenvallemanden is a Featured Member DF Junior DF Donator

    great post mate
     
  11. hugorn
    Offline

    hugorn Guest

    solved
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block