代码示例
// 单行字符串String str = 'abc';//多行字符串String multiLine = '''这是多行文本    能够回车的''';// 字符串连贯形式'Dart ' 'is ' 'fun!'; // 'Dart is fun!''Dart ' + 'is ' + 'fun!'; // 'Dart is fun!''Dart' * 2; // 'DartDart'
String属性
属性形容
List<int> codeUnits获取字符串utf-16编码值的列表
int hashCode获取字符派生的哈希代码
bool isEmpty字符串是否为空
bool isNotEmpty字符串是否不为空
int length获取字符串长度
Runes runes获取字符串utf-16编码值的可迭代列表
Type runtimeType获取运行时的数据类型
String办法
属性形容
int codeUnitAt(int index)返回给定索引值的对应utf-16编码
int compareTo(String other)与传入字符串进行比拟,有雷同返回1,否则返回-1
bool contains(Pattern other, [int index])查找返回字符串是否有符号要求的,传入index规定从index位开始查找
bool endsWith(String other)字符串的结尾是否为传入的值
int indexOf(Pattern other, [int start])从字符串后面开始查找返回合乎规定的第一个的索引地位,传入start规定从哪里开始查找
int lastIndexOf(Pattern other, [int start])与indexOf雷同,不同的是这个办法是从前面开始查找
String padLeft(int width, [String padding])如果字符串没有width的长度,则在后面加上padding字符串并返回,不会扭转原字符串
String padRight(int width, [String padding])padLeft办法雷同,不同的是从padding加在前面
String replaceAll(Pattern from, String to)替换所有匹配的子字符串
String replaceAllMapped(Pattern from, String replace(match))将匹配到的字符串用函数解决后返回字符串替换
String replaceFirst(Pattern from, String to, [int index])替换第一个匹配的子字符串,能够规定从index出开始匹配
String replaceFirstMapped(Pattern from, String replace(match), [int index])replaceAllMapped,此办法只替换第一个匹配的值,能够规定从index处开始匹配
String replaceRange(int start, int end, String to)替换范畴类的字符串
List<String> split(Pattern pattern)拆分字符串为数组
String splitMapJoin(Pattern pattern, { String onMatch(match), String onNonMatch(match) })拆分替换字符串,匹配和不匹配的执行对应函数替换成返回值
bool startsWith(Pattern pattern, [int index])是否是匹配的正则或字符串开始,能够规定从index开始查找
String substring(int startIndex, [int endIndex])提取字符串中startIndex(蕴含)到endIndex(不蕴含)两个指定的索引号之间的字符。
String toLowerCase()把字符串转换为小写
String toUpperCase()把字符串转换为大写
String trim()去除字符串两边的空白
String trimLeft()去除字符串右边的空白
String trimRight()去除字符串左边的空白