09-01-2011 02:06 PM
Hellow LV'ers
Simplified Example
I have a string with 3 digits e.g. input 789
I would like to use scan string to place a "." between the digits.
input 789 output 7.8.9
How do I set up the scan string to do this?
Thanks
Solved! Go to Solution.
09-01-2011 02:34 PM - edited 09-01-2011 02:36 PM
The simple answer is that you can't. Scan from string is not used to insert of format new strings. It is for pulling items out of strings.
However, here is an example that does what you want using regular expressions.
This example will only work for strings that are three digits long. You could modify it to use a loop which will work for any length string. If you use a loop you will only pick a single digit at a time from the string so your regular expression would be "(\d)".
09-01-2011 02:52 PM - edited 09-01-2011 02:53 PM
Of course a general solution needs to be more scalable. I don't think we can assume that there are always exactly three numbers, because this was only given as a "simplified example". 😄
Here is a solution that works for any length string (containing decimal digits exclusively)
(of course you need to ensure that the input is sane and does not contain any illegal characters. not shown, but look at lexical class)
09-01-2011 02:56 PM
This should work too
09-01-2011 03:01 PM
Steve, you are very conflicted at the moment. Having 2010 in the signature and posting a 2011 snippet. 😄
09-01-2011 03:04 PM
How about now
09-01-2011 04:11 PM
smallest and most versatile!! I love it, thank you as usual mighty altenbach
09-01-2011 04:44 PM