Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Casting text to nat #91

Answered by rscrivens
i-jared asked this question in Q&A
Discussion options

You must be logged in to vote

I don't know if there's a built in way to do this, quick search I couldn't find a toNat from Text. But you could make a function, that takes a string, for loops through its characters, pass it through a switch that matches the character with a 0-9 character, and then build out the number, multiplying the previous number by 10 and adding the new number:
"1357"
'1' -> (0 * 10) + 1
'3' -> (1 * 10) + 3
'5' ->(13 * 10) + 5
'7' -> (135 * 10) + 7
1357

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by professionalGithub99
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants