Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

check if string contains all numeric data

Posted on 2006-07-07
1
455 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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