Conver a string to int

Hi,

I need to convert a string to an integer. Is there any function in DXL for this ?
What I want to do is to read a configuration file with Attribute Type names an default/min/max values and the create these attribute types e.g. on module creation ...

Something like that:

  1. Base Type | Type Name |Values (Enum) |Min Val|Max Val|
Enumeration|SG_Type_Stakeholder|Line,Main,Safety| | |
Enumeration|SG_Type_Status|Draft,Proposed,Released| | |
Enumeration|SG_Type_TargetRelease|FELTON,AMIKI,BIRKI| | |
Integer|SG_Type_Effort||-1|99|
String|SG_Type_ID||||
Real|SG_Type_Real||||
Text|SG_Type_Text||||
Date|SG_Type_Date||||
Username|SG_Type_Username||||

CurrentlyI read the file into a text buffer (line by line), tokenize it and then create the attribute type from the single tokens -- this works fine for the Enumeration type, but for the Integer a need a 'int' parameter ...

XML would be much better, but as I understood, there is currently no way ....
Regards,
Patrick
SystemAdmin - Wed Jul 22 05:20:49 EDT 2009

Re: Conver a string to int
IBM_Gust - Wed Jul 22 08:49:40 EDT 2009

Following works:

string s="99"
int i = intOf(s)
print i ""

Re: Conver a string to int
SystemAdmin - Wed Jul 22 09:06:55 EDT 2009

IBM_Gust - Wed Jul 22 08:49:40 EDT 2009
Following works:

string s="99"
int i = intOf(s)
print i ""

There is also a function isValidInt to check the string before conversion to integer. For some reason this is documented in DXL Help, but "int intOf(string)" is mentioned only briefly.

Re: Conver a string to int
SystemAdmin - Wed Jul 22 10:38:10 EDT 2009

IBM_Gust - Wed Jul 22 08:49:40 EDT 2009
Following works:

string s="99"
int i = intOf(s)
print i ""

So easy! I didn't found anything in the doc's (and I didn't try this one ...)
Thanks a lot!

Re: Conver a string to int
llandale - Wed Jul 22 13:50:18 EDT 2009

Yes, as others said use:
int intOf(string)
bool isValidInt(string)

You may want to write a library function to do it, testing it with strange and invalid strings:
-001, 00-1, abcde, 999999999999999999999

If the string is invalid, you need to decide if the function returns zero or minus-one.

  • Louie