Solved

check if string contains all numeric data

Posted on 2006-07-07
1
456 Views
Last Modified: 2010-05-18
I'm sure this is very easy to do, I need to check if a string to see if it only contains numbers I was wondering if there was a built in function for something like this.  Also is there a built in function to search a string for a particular character.
0
Comment
Question by:ICPooreman
1 Comment
 
LVL 17

Accepted Solution

by:
geobul earned 75 total points
ID: 17058236
Hi,

About your second question see Pos function:

i := Pos('x', StrVar);

About the first one:

function IsNumeric(const s: string): boolean;
var i: integer;
begin
  result := false;
  for i := 1 to Length(s) do begin
    if not (s[i] in ['0'..'9']) then exit;
  end;
  result := true;
end;

// usage:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if IsNumeric(Edit1.Text) then ShowMessage('OK');
end;

Regards, Geo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question