Finding '.' with string.find()

前端 未结 3 1692
夕颜
夕颜 2021-01-04 18:47

I\'m trying to make a simple string manipulation: getting the a file\'s name, without the extension. Only, string.find() seem to have an issue with dots:

<
3条回答
  •  失恋的感觉
    2021-01-04 19:31

    The other answers have already explained what's wrong. For completeness, if you're only interested in the file's base name you can use string.match. For example:

    string.match("crate.png", "(%w+)%.")  --> "crate"
    

提交回复
热议问题