zoukankan      html  css  js  c++  java
  • Dart语言学习(四)Dart字符串

    一、字符串的创建

    使用 单引号,双引号 创建字符串

    使用 三个引号或双引号 创建多行字符串

    使用 r 创建原始 raw 字符串

      String str1 = 'Hello';//""
      String str2 = '''Hello
                      Dart''';//"""
      print(str1);
      print(str2);
    
    //  String str3 = 'Hello 
     Dart';
      String str3 = r'Hello 
     Dart';
      print(str3);

    输出

    Hello
    Hello
                      Dart
    Hello 
     Dart

    二、字符串操作

    其他常用方法如下:

     

      String str4 = "This is my favorite language";
      print(str4 + "New");
      print(str4 * 5);
      print(str3 == str4);
      print(str4[1]);
    
      int a = 1;
      int b = 2;
      print("a + b = ${a + b}");
      print("a = $a");
    
      print(str4.length);
      print(str4.isEmpty);
    
      print(str4.contains("This"));
      print(str4.substring(0,3));
      print(str4.startsWith("a"));
      print(str4.endsWith("ge"));
    
      var list = str4.split(" ");
      print(list);
    
      print(str4.replaceAll("This", "That"));

    输出:

    This is my favorite languageNew
    This is my favorite languageThis is my favorite languageThis is my favorite languageThis is my favorite languageThis is my favorite language
    false
    h
    a + b = 3
    a = 1
    28
    false
    true
    Thi
    false
    true
    [This, is, my, favorite, language]
    That is my favorite language
    Dart学习系列文章:https://www.cnblogs.com/jukaiit/category/1636484.html
  • 相关阅读:
    面向对象(Object Oriented)
    文件操作
    函数
    dict--字典
    list--列表
    Ubuntu_18.04安装网易云音乐
    初识数据类型
    css控制内容显示,自动加"..."
    css固定元素位置(fixed)
    解决IE下iframe默认有白色背景的bug
  • 原文地址:https://www.cnblogs.com/jukaiit/p/12235055.html
Copyright © 2011-2022 走看看