Great Tutorial- Reading And Writing With Files

 
#1

I don't find the right place to post comments on tutorials, but just wanted to compliment @JustinRatliff on his great tutorial on File Operations with example scripts

Regards,
Frank

#2

Thank you Frank, very much! I appreciate the positive feedback Smile Smile Smile

#3

@JustinRatliff
I was able to run all of your examples without any issues, but when I used my own data I had some problems with a feature of Split()

A string consisting of alpha chars or mixed alpha and numeric work as I expected, but a string of just numbers is treated as math. This is by design according to an old post I found


User-inserted image

Here is some code and the results showing the issue I can into:

Code:


ClearVariables()

$Chars= ("A,B,C")
$CharsSplit= Split( $Chars, "," , 0 )
Print( "$CharsSplit= " + $CharsSplit)

$Numbers= ("1,2,3")
$NumbersSplit= Split( $Numbers, "," , 0 )
Print( "$NumbersSplit= " + $NumbersSplit)



User-inserted image

I was able to solve my problem by adding one field of alpha to my numeric data.

It might be helpful to add a caution to your great tutorial

Also, it appears that the Script manual states that Split() returns an index instead of the value found

http://www.ez-robot.com/Tutorials/UserTutorials/169/1

User-inserted image


Thanks again for your fine work on the tutorial
Frank

#4

A number is a number and a string is a string. A number is not a string because a number is used for math. Math uses numbers, not strings. So if you put a number in a variable, the type becomes a number. However, you can still parse/split a list of numbers by adding commas and using the split() command.

Code:


$x = "1, 2, 3, 4"

$val = split($x, ",", 2)

print($val)




*note: i updated the ez-script manual to reflect the misprint for Split(), thanks!

#5

@DJSures
Thanks for clearing that up! I did have the commas, neglected to add a spaces as you did in your example

I ran a test and adding the spaces to my code worked and I found out there was no need for the parentheses

Code:


ClearVariables()

$x = "1, 2, 3, 4" # note the spaces
$val = split($x, ",", 3)
print($val)

$x= "1,2,3" # note NO spaces
$val= Split( $x, "," , 0 )
Print( $val)

$x= "1 ,2, 3" # added spaces
$val = split($x, "," , 0 )
Print( $val)

$x= ("1, 2, 3") # added space and parentheses
$val = split($x, "," , 0 )
Print( $val)



User-inserted image

Thanks for the quick response
Frank