| | |
Parsing a string. Need help
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2009
Posts: 9
Reputation:
Solved Threads: 0
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
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
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.
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.
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
Or a simple try... except...end block such as
IntToStrDef sounds easier.
Pascal and Delphi Syntax (Toggle Plain Text)
function IsInteger(MyString:string):boolean; begin try Result:=true; strtoint(MyString); except Result:=false; end; end;
IntToStrDef sounds easier.
Last edited by m610; Mar 19th, 2009 at 1:32 pm.
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: Mar 2009
Posts: 9
Reputation:
Solved Threads: 0
•
•
•
•
Or a simple try... except...end block such as
Pascal and Delphi Syntax (Toggle Plain Text)
function IsInteger(MyString:string):boolean; begin try Result:=true; strtoint(MyString); except Result:=false; end; end;
IntToStrDef sounds easier.
![]() |
Similar Threads
- Parsing String (Java)
- parsing a string (xml) in C (C)
- Parsing a String in Ksh (Shell Scripting)
- Parsing a String (Java)
- repost: leak using c++ string (C++)
- leak using c++ string (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: How to use bluetooth libs with Delphi 7
- Next Thread: Terminating a thread in OnDestroy
Views: 901 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi





