Repository navigation
String to Integer and Float #207
mittelmark
started this conversation in
General
Replies: 2 comments 10 replies
|
In the //FAIL: java js py swift ts clsays the test is expected to fail on Java, JavaScript, Python, Swift, TypeScript and OpenCL. So no, it's not implemented for Python. But the test passes for D. A quick workaround could be: static int ParseInt(string s)
{
if (s.Length == 0)
handleError();
int i = 0;
for (int d in s) {
if (d < '0' || d > '9')
handleError();
i = i * 10 + d - '0';
}
return i;
}And handle overflows and negative numbers. |
3 replies
|
BTW: The loop in the workaround suggestion should be a foreach - |
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
After finding IntTryParse in the test directory and TryParse in the discussion forum, I gave these code chunks a test but could get that working for Python or D which I tried. I gave as well native a try, but could not get the code for Python properly indented. Is there a possibility to convert a string to an integer or a float/double in a cross language way? Let's assume that we have checked before that the string contains only numeric characters for instance using a regular expression.
Best,
Detlef
All reactions