This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
diegodan1893's profile picture

[Lua][Question]How to get the last part of a path?

Started by diegodan1893, 21 October 2012 - 01:29 PM
diegodan1893 #1
Posted 21 October 2012 - 03:29 PM
I want to get the last part of a path (a string). For example:

string="/programs/tests/helloWorld"

I need to get only the "helloWorld" part in another variable. How can I do that?
Jasonfran #2
Posted 21 October 2012 - 04:01 PM
This thread should help you
http://www.computercraft.info/forums2/index.php?/topic/5263-split-strings-into-an-array/page__pid__42809#entry42809
diegodan1893 #3
Posted 21 October 2012 - 04:19 PM
This thread should help you
http://www.computerc...2809#entry42809

Edit: It didn't work. I do the same but with the pattern "/" but it returns only the "/". Do you know how to get the text betwen the "/"?
Lyqyd #4
Posted 21 October 2012 - 05:35 PM
I want to get the last part of a path (a string). For example:

string="/programs/tests/helloWorld"

I need to get only the "helloWorld" part in another variable. How can I do that?

fs.getName()
diegodan1893 #5
Posted 21 October 2012 - 05:55 PM
fs.getName()

Thanks, I forget that that function exists xd.
sjele #6
Posted 21 October 2012 - 07:19 PM
or you could do this to get it.

string="/programs/tests/helloWorld"
local file = string.match(string, "/(%w+)$")