I am trying to slice a section of a string to obtain a specific section of that string.
Here is an example in Python:
import os
my_string = "filesizec:\\users\\nate\\desktop\\thepark.jpg"
new_string = my_string[8:]
print(new_string)
file_size = os.path.getsize(new_string)
print("The file's size is:", file_size)
File Output:
c:\users\nater\desktop\thepark.jpg
The file's size is: 1413139
Notice how the file path was cut and used in a variable and the word filesize was ignored. Just trying to take a string and slice out the part I need. In this case, I didn't know how long the file path was so by using the [8:], I was able to state the starting point but the ending point was everything left going to the right. Need to do this same thing in nim. Any help would be highly appreicated. Nim's slicing syntax is different but not that far off:
let mystr = "Hello world!"
echo mystr[5..^1] # prints " world!"
Wow, I see. That helps a ton!
Thanks for the help.
To Translate your python code to nim using the string slice:
import os
let myString = "filesizec:\\users\\nate\\desktop\\thepark.jpg"
let newString = myString[8..^1]
echo newString
let fileSize = getFileSize(newString)
echo "The file's size is: ", fileSize, " bytes"