如何实现类似于:How to get a substring between two strings in PHP?但在DART中的解决方案

For example I have a String:
String data = "the quick brown fox jumps over the lazy dog"
I have two other Strings: quick and over
I want the data inside these two Strings and expecting result:
brown fox jumps

推荐答案

您可以使用String.indexOfString.substring组合使用:

void main() {
  const str = "the quick brown fox jumps over the lazy dog";
  const start = "quick";
  const end = "over";

  final startIndex = str.indexOf(start);
  final endIndex = str.indexOf(end, startIndex + start.length);

  print(str.substring(startIndex + start.length, endIndex)); // brown fox jumps
}

另请注意,startIndexinclusive,而endIndexexclusive.

Flutter相关问答推荐

为什么我不能看到类音频源在flutter?'

Android Emulator冻结,但在调整窗口大小时解冻

遇到图像路径格式问题

如何在容器小部件中的图像旁边添加文本?

try 使用fl_Chart of Ffltter,但在导入它时遇到以下错误:Error:';TextScaler';is;t a type

如何管理枚举类型的阻塞事件?

如何使DropDownMenu宽度等于TextFormfield?

Flutter 日期时间格式

Ffltter Firebase向用户添加公司

如何在flutter中将所有单词的第一个字母大写

Flutter应用无法上传到Microsoft Store

如何在Flutter中显示ListView Builder区域外的列表数据?

如何在android中 Select 任何文件/文件路径 - Flutter

如何在 Flutter (iOS) 中解决这个问题

通过点击缩略图加载全屏图像

我怎样才能一次只选中一个复选框?

我正在try 使用 Firebase 在 Flutter 中使用 Google 注销,但它不起作用

Future.wait() 中的 futures 可以顺序调用吗?

为什么 Flutter riverpod 直接分配不起作用但方法可以

在 Flutter 中,如何使用文本字段和方形图像进行行布局