943,807 Members | Top Members by Rank

Ad:
Mar 18th, 2009
0

Parsing a string. Need help

Expand Post »
Hello,
I am new to delphi. I have a problem. I have a string which can be of any length. Sometimes with delimiter characters for printing in new line.
Now I need to distinguish whether the received string is a number (both -ve and +ve) or any other alpha numeric value. Based on that I need to proceed further.
Any built in function to check this? or how to parse and find out its a number?

regards,
Anand
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anandkrishnantc is offline Offline
10 posts
since Mar 2009
Mar 18th, 2009
0

Re: Parsing a string. Need help

There are a number of conversion functions the sysutils.pas unit that can test this for you and check out extractstrings in the Classes unit for a basic parsing function.
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007
Mar 19th, 2009
0

Re: Parsing a string. Need help

I'm not good in delphi...but I want to help you
I looked for you problem on the web,and there was a good idea for your problem.They say:Try to convert that string into number.The StrToIntDef takes an extra argument that is returned, if the string could not be converted to int successfully.
Last edited by FlamingClaw; Mar 19th, 2009 at 10:28 am.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 19th, 2009
0

Re: Parsing a string. Need help

Or a simple try... except...end block such as

Pascal and Delphi Syntax (Toggle Plain Text)
  1. function IsInteger(MyString:string):boolean;
  2. begin
  3. try
  4. Result:=true;
  5. strtoint(MyString);
  6. except
  7. Result:=false;
  8. end;
  9. end;

IntToStrDef sounds easier.
Last edited by m610; Mar 19th, 2009 at 1:32 pm.
Reputation Points: 10
Solved Threads: 1
Light Poster
m610 is offline Offline
40 posts
since Oct 2008
Mar 19th, 2009
0

Re: Parsing a string. Need help

By the way, I had not known about the StrToIntDef function until reading this thread. I checked with Help in my copy of Delphi 6, which is where I have learned most of my Delphi programming, and it did not list it. Then I looked in SysUtils.pas and found it, along with some other nice functions I wish I had known about, such as:

function StrToFloatDef(const S: string; const Default: Extended): Extended;

and

function TryStrToFloat(const S: string; out Value: Extended): Boolean;

I'll be digging around in there a bit more for other things I have missed, like the string-to-int function that converts strings, including hex-formatted strings, to integers.
Reputation Points: 10
Solved Threads: 1
Light Poster
m610 is offline Offline
40 posts
since Oct 2008
Mar 23rd, 2009
0

Re: Parsing a string. Need help

Hello, thanks for the replies. I have a text (Widestring). Which need to be checked (no need or converting it ), if its a float or not. When I tried TexttoFloat, the program behaves worgly. No proper ending of the method.
and I see all the text ends with #0 . should I remove this trailing #0 ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anandkrishnantc is offline Offline
10 posts
since Mar 2009
Mar 23rd, 2009
0

Re: Parsing a string. Need help

Click to Expand / Collapse  Quote originally posted by m610 ...
Or a simple try... except...end block such as

Pascal and Delphi Syntax (Toggle Plain Text)
  1. function IsInteger(MyString:string):boolean;
  2. begin
  3. try
  4. Result:=true;
  5. strtoint(MyString);
  6. except
  7. Result:=false;
  8. end;
  9. end;

IntToStrDef sounds easier.
It worked. thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anandkrishnantc is offline Offline
10 posts
since Mar 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: How to use bluetooth libs with Delphi 7
Next Thread in Pascal and Delphi Forum Timeline: Terminating a thread in OnDestroy





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC