7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dartで末尾一文字だけを削除する

7
Posted at

やりたいこと

hoge/foo/bar/ という文字列から末尾/を取り除き、hoge/foo/barとしたい。

やり方

final str = 'hoge/foo/bar/';
// 末尾'/'の場所を返す
final pos = str.length - 1;
// 最初からposまでの部分文字列を取得
final result = str.substring(0, pos);
print(result);
// hoge/foo/bar

参考

dart - Flutter - Remove String after certain character? - Stack Overflow

7
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?