user11065582
user11065582

Reputation:

Removing trailing slash in a String

Some users type https://google.com/ and some users type https://google.com

How to check If user type with slash or not? If user type with a slash How to remove slash?

Upvotes: 3

Views: 1924

Answers (2)

user603749
user603749

Reputation: 1763

If you re doing lots of string manipulations you can use a sanitize package https://pub.dev/documentation/validators/latest/sanitizers/sanitizers-library.html, in your case it would be rtrim(str, ' /')

Upvotes: 2

user10539074
user10539074

Reputation:

var str = 'https://google.com/';
if (str.endsWith('/')) str = str.substring(0, str.length - 1);

Upvotes: 3

Related Questions