Dart 中的 substring()函数

首页 / Dart入门教程 / Dart 中的 substring()函数

返回此字符串的子字符串,该子字符串从startIndex(包括在内)到endIndex(不包括)之间。

substring - 语法

substring(int startIndex, [ int endIndex ])
  • startIndex   - 开始从(包括)开始提取的索引。

  • endIndex     - 停止提取的索引(专有)。

注意-索引从零开始,即第一个字符的索引为0,依此类推。

substring - 返回类型

返回一个字符串。

substring - 示例

void main() { 
   String str1="Hello Learnfk"; 
   print("New String: ${str1.substring(6)}"); 
   
   //from index 6 to the last index 
   print("New String: ${str1.substring(2,6)}"); 
   
   //from index 2 to the 6th index 
} 

它将产生以下输出-。

链接:https://www.learnfk.comhttps://www.learnfk.com/dart-programming/dart-programming-substring-method.html

来源:LearnFk无涯教程网

New String: Learnfk 
New String: llo 

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Service Mesh实践指南 -〔周晶〕

技术管理实战36讲 -〔刘建国〕

如何设计一个秒杀系统 -〔许令波〕

接口测试入门课 -〔陈磊〕

互联网人的英语私教课 -〔陈亦峰〕

Web安全攻防实战 -〔王昊天〕

Redis源码剖析与实战 -〔蒋德钧〕

HarmonyOS快速入门与实战 -〔QCon+案例研习社〕

深入浅出可观测性 -〔翁一磊〕

好记忆不如烂笔头。留下您的足迹吧 :)