user11065582
user11065582

Reputation:

How to remove dot(.) on String in Flutter?

assets/images/Defect/icon-5.svg

I need to get svg on above String

example:

print(path);

output only svg

Upvotes: 4

Views: 6209

Answers (3)

danypata
danypata

Reputation: 10175

There is a function called extension in package:path/path.dart that will give you the extension of a file. If you want to remove the . from that extension you just need to replace it with an empty space, something like:


    import 'package:path/path.dart';

    String svg = extension("assets/images/Defect/icon-5.svg");
    svg = svg.replaceAll(".", "");
    print(svg);

Reference here

Upvotes: 6

Ferdi
Ferdi

Reputation: 788

path.split('.')[1]

The documentation for the split function is here

Upvotes: 3

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76213

path.substring(path.lastIndexOf('.')).substring(1)

Upvotes: 3

Related Questions