How to split the string 12345?
Well, basic question is, I have a string that is "12345". How do i split it up? Tried using tokenizer but I failed.
Oldpost:
Not exactly sure how to explain this, but say you have the number 12345 as a value, how could i retrieve one of the numbers from that value and use it seperatly? Im failing to explain, but the 4 in "12345" is equal to 40 and the 3 is equal to 300, the 2 is equal to 2000, ect. How Could i retrieve these values? Is there an extension or a math equation? I have tried dividing the number by 10 or 100 but it don't really help seeing as I get decimals and such. Sorry if this made no sense, but if it did, anyone care to help? Thanks in advance!
By the way, hi, i'm new here :D
Re: Is there a way to retrieve a value from a value?
Off the top of my head, convert it to a string, retrieve the number from the position you need, conver that to a value, then multiply it by 10,100,etc as required.
I'm sure there's a more efficient way, but I need to log off now!
Re: Is there a way to retrieve a value from a value?
Seems efficient to me :D
This is great! This question has bugged me for a year now and I never really thought of converting it to a string.
How would I go about retrieving the number from the position I need? Thanks for answering :D
EDIT: Just discovered "String Tokenizer". Guessing thats how to do it! Ima fiddle round with this :D
EDITAGAIN: Ok, seem's to be exactly what I need, but I'm not sure on how to set the delimiter to split the whole string up.
Re: Is there a way to retrieve a value from a value?
No need for any extensions. Just use the Built-In function of MMF2 that has its own button in the expression editor. Mid$. is what you need. Give it a string, the location in the string to start at, and how many characters to get. For example:
Mid$("Hello! How are you?", 5, 6)
would give
"! How "
Re: Is there a way to retrieve a value from a value?
Wow thanks!
Sorry for being such a newbie, but I have stumbled across an error again.
So for the units column It was a success when I wrote
Mid$("12345", 1, 1)
It retrieved 5
But when I try to get the next column, following what you wrote, I tried this:
Mid$("12345", 2, 1)
It retrieved 0
2 was the location to start at, and 1 was how many characters to get. What have I done wrong? Thanks
Re: Is there a way to retrieve a value from a value?
Are you sure? It works fine here; it returns "3" like it should. See the example:
http://mfa.aquadasoft.com/view/1276998262-Mid
Re: Is there a way to retrieve a value from a value?
Looked at your example.
It's helped me figure out whats wrong.
I assumed that the string would flip for some reason...
Meaning the number "12345" would become "54321" when converted into a string. Opps! Thanks though, I know exactly what im doing now!
Re: Is there a way to retrieve a value from a value?
If you don't want to perform string conversions you can use this expression:
([color:#009900]12345[/color]/Int(10 pow ([color:#FF0000]digits[/color]-1))*10 pow ([color:#FF0000]digits[/color]-1)) mod 10 pow [color:#FF0000]digits[/color]
If you set digits to e.g. 4, this expression will return 2000. If you set digits to 2 you'll get 40.
Re: Is there a way to retrieve a value from a value?
Isn't that the Extended Form thing we learned in first grade? 10000 + 2000 + 300 + 40 + 5
Re: Is there a way to retrieve a value from a value?
Yes. Now in delicious single-expression form.
Re: Is there a way to retrieve a value from a value?
In the post with number :
#194439
You mentioned how the string seperator selected the number wrong. You said:
Mid$("12345", 1, 1)
It retrieved 5
(I believe Mid goes form the middle, in this case it was one number after it, and then 1 number after that number.
Which the middle would be 3, and one after it would be 4, and then it goes to 5. I think if there is 2 numbers it chooses the last.
But when I try to get the next column, following what you wrote, I tried this:
Mid$("12345", 2, 1)
It retrieved 0
(It started at 5 , which is 2 numbers from 3, which is middle, and went one more number and chose the last one to output. There wasnt a number after 5, so instead of crashing because of "null", it gives 0.
--------------------------
Well i think Mid$ is grabbing numbers form the middle and rounding the end number selected if the number of items is uneven. There might be a different way to select and splice elements from a string other than this function. It uses similar syntax as described and may be similar to visual basic way of selecting numbers. Remember the first element in anything is always 0, so 0,1 would start at zero and select 1 elements past it.
Re: Is there a way to retrieve a value from a value?
Wha?
EDIT:
To be clear: Mid$'s parameters are the start position, counting from the left (first character is 0), and a count. As per the MMF2 docs, Mid$("Hello",1,3) gives "ell" (skip one character from the left, then get 3).
Re: Is there a way to retrieve a value from a value?
Mid$ returns a string, hence the $ in the expression Mid$. If there were nothing to retun it DOES NOT return "0", it returns "". If it returns "0" and you have no zero in your string then you need to check everything, ebcause "12345" doesn't have a single "0" anywhere. ;)
Re: Is there a way to retrieve a value from a value?
GameDevs: Don't make any conclusion out of what numbers that Mid$ was supposed to return in that previous post. Mid$("12345", 1, 1) was said to return 5, and Mid$("12345", 2, 1) was said to return 0.
...both statements are incorrect. Mid$("12345", 1, 1) returns 2 and Mid$("12345", 2, 1) returns 3.
Then, I of course recommend the expression in my previous post. Don't convert things to strings if the operation can be carried out with numbers.