Search code examples
stringcase-insensitivenim-lang

Check if a string ends with something, case insensitive?


I want to check if a file has a certain extension, which I can do with filename.endsWith(".ext"). But I also want to match against .EXT. How can I do this?


Solution

  • The easiest is probably filename.toLowerAscii.endsWith(".ext"). You should however consider using splitFile to get the extension and then simply compare it to ".ext" after turning it lowercase.