I have the following line read in from my text file: "1200, 1200"
and I want to split the string on the ", "
such that I can access the raw numbers. How can I do that in Julia?
Check out this comprehensive article on Splitting Strings in Julia.
Julia has a simple split
function which takes in two arguments. The first is the string you want to split and the second is the delimiter (the thing you want to split on/by). Both parameters that are passed to the split function should be strings.
In this example:
data = readlines("numbers.txt") # Returns a one dimensional array of strings.
xmin, ymin = split(data[1], ", ") # data[1] indexs into that 1-D array to get the string
we read in all of the data from a text file which is just simple "1200, 1400".
We can then use the split
function to separate the two numbers into "xmin" and "ymin". In this example, after the code is run, "xmin" will be equal to 1200 and "ymin" will be equal to 1400.
Read more about the split
function in the Julia docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With