Created with <3 with dartpad.dev.
Created
January 19, 2024 06:52
-
-
Save matifdeveloper/1d024485336480a5e48940a3758c0468 to your computer and use it in GitHub Desktop.
File extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String path = "assets/images/abc.svg"; | |
String file = path.fileExtension(); | |
print("File extension: $file"); | |
} | |
extension StringExtension on String { | |
String fileExtension() { | |
int dotIndex = lastIndexOf('.'); | |
if (dotIndex != -1 && dotIndex < length - 1) { | |
return substring(dotIndex + 1); | |
} else { | |
return ""; // No extension found | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment