Reputation: 19514
String abc = 'abc.jpg';
//or
String abc = 'abc.png';
//or
String abc = 'abc.xxxx';
How to remove .png or .jpg or .xxxx?
I tried this way. But not working
print(abc.replaceAll(RegExp("\.\$"),''));
Upvotes: 1
Views: 1743
Reputation: 49
str.toStringAsFixed(0);
simply add this to your string it removes the string after the dot(.).
Upvotes: 0
Reputation: 397
try this:-
print(abc.split(RegExp(r"(\.+)"))[0]);
Hope it will work
Upvotes: 3
Reputation: 338
With regular expression:
https://stackoverflow.com/a/624877/8619512
Try this:
(.+?)(.[^.]*$|$) This will:
Capture filenames that start with a dot (e.g. ".logs" is a file named ".logs", not a file extension), which is common in Unix. Gets everything but the last dot: "foo.bar.jpeg" gets you "foo.bar". Handles files with no dot: "secret-letter" gets you "secret-letter".
Upvotes: 1
Reputation: 714
Try with :
print(abc.replaceAll('.', ''));
or
with Regx:
print(abc.replaceAll(RegExp('[^a-z0-9_]+'),''));
Upvotes: 3