美文网首页
dart 基础

dart 基础

作者: 帅气的阿斌 | 来源:发表于2021-04-17 16:44 被阅读0次
void main(List<String> args) {
  dart_string();
}

//字符串操作
void dart_string() {
  //字符串输出
  String student1 = "zhang san";
  print("student1 = ${student1}");

  String student2 = "list";
  print("student2 = ${student2}");

  String addString = student1 + "和" + student2;
  print("addstring = ${addString}");

  //大小写
  String upper = addString.toUpperCase();
  String lower = addString.toLowerCase();
  print("upper ${upper} - lower ${lower}");

  //类型转换
  String count = "10";
  int countInt = int.parse(count);
  print("类型转换=${countInt}");

  //转字符串
  String count_to_string = countInt.toString();

  //小数精度保留 <=5舍 >5入
  print("小数精度 = ${3.33350.toStringAsFixed(3)}");
  print("小数精度 = ${3.33351.toStringAsFixed(3)}");

  //字符串分割
  String splitstring = "1,2,3,4,5";

  List spliteResult = splitstring.split(",");
  List<String> spliteResult2 = splitstring.split(",");
  print("${spliteResult}\n${spliteResult2}");

  String splitMapJoin = splitstring.splitMapJoin(",", onMatch: (Match match) {
    return "x";//替换条件中的字符串
  }, onNonMatch: (String onNonMatch) {
    return "a";//替换非条件中的字符串
  });
  //splitMapJoin = axaxaxaxa
  print("splitMapJoin = ${splitMapJoin}");

  //字符串 开头 尾部 匹配
  String headfooter = "headbodyfooter";
  bool startsWith = headfooter.startsWith("head");
  bool endsWith = headfooter.endsWith("footer");
  bool contains = headfooter.contains("body");
  //从索引开始匹配字符,后面只要含有搜索字符则为true
  bool containsWithIndex = headfooter.contains("body", 1);

  //字符串替换
   headfooter.replaceAll("o", "xx");

}

相关文章

  • Dart 基础(四)

    前言笔者在之前已经写了3篇Dart的基础文章了。Dart 基础 (一)Dart 基础 (二)Dart 基础 (三)...

  • Dart 基础 (三)

    前言笔者在之前已经写了2篇Dart的基础文章了。Dart 基础 (一)Dart 基础 (二) 本文是Dart基础的...

  • dart入门潜修系列教程

    dart入门潜修基础篇之基本语法和内置类型dart入门潜修基础篇之方法dart入门潜修基础篇之操作符dart入门潜...

  • 一.Dart语法-操作符、方法与异常

    Dart基础 运行Dart 代码可以使用 dart xxx.dart,dart命令需要配置环境变量,将 “${F...

  • Dart基础(一)

    级别: ★☆☆☆☆标签:「Flutter 」「Dart」「Dart基础类型」作者: WYW审校: QiShare...

  • Flutter学习笔记

    Dart基础语法 一、选择开发工具 首先需要安装Dart SDK(https://www.dart-china.o...

  • Dart语言基础,Dart 基础

    Dart 的main方法有两种声明方式 注释 变量的声明 、命名规则、数组类型 Dart是一个强大的脚本类语言,可...

  • Dart 基础

    Dart 基础汇总 点我直达[https://xxxixxxx.github.io/categories/Dart...

  • Flutter - 入门

    Dart基础 如果你有JS、Java、Kotlin、Swift等语言的基础,入门几乎没啥子难度 程序入口 dart...

  • Dart record

    参考 Dart学习笔记(29):异步编程Dart编程字典子不语归来 的 Dart2基础何小有Dart实例教程 数组...

网友评论

      本文标题:dart 基础

      本文链接:https://www.haomeiwen.com/subject/xxkdlltx.html