• Home
  • Contact Me
  • About Me
  • Resources
  • Favorites
  • Earn Money

Wednesday, October 1, 2008

EGL: Converting string to int

Enterprise Generation Language (EGL) is coming up great. It has provided a good many number of API's. However sometime we need to rely on Java api to do some small task. For example converting string to int or any other datatype conversion. There is nothing great in converting string to int in EGL. We just need to do something like below:
resultInt int = JavaLib.invoke("java.lang.Integer", "parseInt", "12345");
if we print resultInt obviously the result would be "12345". So far so good. Now try to change the string to "9999999999" and execute the program again. Output will be something like
For input string: "9999999999" and the execution will stop by then. What is the reason for this behavior? This is because we are NOT handling exception. Try below snippet:
try
resultInt int = JavaLib.invoke("java.lang.Integer", "parseInt", "12345");
onException (e AnyException)
//assign some value as per business
resultInt = -1;
end
Regards
Monu

1 comment:

Anonymous said...

You can do it easier with the AS operator: "1234" as int.