Jump to content




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


  • You cannot reply to this topic
5 replies to this topic

#1 diegodan1893

  • Members
  • 164 posts
  • LocationSpain

Posted 21 October 2012 - 02: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?

#2 Jasonfran

  • Members
  • 148 posts
  • LocationEngland

Posted 21 October 2012 - 03:01 PM

This thread should help you
http://www.computerc...2809#entry42809

#3 diegodan1893

  • Members
  • 164 posts
  • LocationSpain

Posted 21 October 2012 - 03:19 PM

View PostJasonfran, on 21 October 2012 - 03:01 PM, said:

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 "/"?

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 October 2012 - 04:35 PM

View Postdiegodan1893, on 21 October 2012 - 02:29 PM, said:

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()

#5 diegodan1893

  • Members
  • 164 posts
  • LocationSpain

Posted 21 October 2012 - 04:55 PM

View PostLyqyd, on 21 October 2012 - 04:35 PM, said:

fs.getName()

Thanks, I forget that that function exists xd.

#6 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 21 October 2012 - 06:19 PM

or you could do this to get it.
string="/programs/tests/helloWorld"
local file = string.match(string, "/(%w+)$")






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users