floor地板,ceil天花板
String str = '''xxx''' //声明多行字符串
<!DOCTYPE html>
<html lang="en">
<head>
<title>这是标题</title>
</head>
<boby>
<h1>
hello
</h1>
<p>
</p>
</boby>
</html>
来声明一个变量
代表的是不在乎具体的类型,但是可以根据等号后面的值来推断当前的类型
如果声明的时候指定了一个具体的类型或者推断出来具体类型,后面就不能随意更改类型了
支持类型推断,想用具体类型直接用具体类型代替
list常用方法
1,length
2,add(,insert()
3, remove(), clear(0
4, indexOf0),lastlndexOf0) 5, sort(), sublist()
6, shuffle0, asMap(), forEach0
字符串的操作:
运算符:+ * ==判断字符串是否相等 []截取字符串
插值表达式
int a = 1;
int b = 2;
print("a + b = ${a + b}"); //a + b = 3
print("a = $a"); //a = 1常用属性:
length isEmpty
常用方法:
contains() substring() startswith() endswith()
字符串 常用方法
字符串操作
```dart
void main() {
String s = "string";
print("s = $s");
String replaceAll = "string string".replaceAll("s", "S");
print("replaceAll = $replaceAll");
String replaceFirst = "string string".replaceFirst("s", "s");
print("replaceFirst = $replaceFirst");
String replaceFirstMapped = "string string".replaceFirstMapped("s", (match) => null);
print("replaceFirstMapped = $replaceFirstMapped");
String replaceAllMapped = "string string".replaceAllMapped("s", (match) => null);
print("replaceAllMapped = $replaceAllMapped");
String replaceRange = "string string".replaceRange(0, 1, "S");
print("rreplaceRange = $replaceRange");
}
```
方法
contains(), substring()
startsWith(), endsWith()
indexOf(), lastIndexOf()
toLowerCase(), toUpperCase()
trim(), trimLeft(), trimRight()
split(), replace???()
属性 length, isEmpty, isNotEmpty
+
*
==
[]
${}
```dart
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-01-01
*
* @description
* @augments
* @example
*
*/
void main() {
String single_quote = 'signle quote string';
print("single_quote = ${single_quote}");
String double_quote = "double quote string";
print("double_quote = ${double_quote}");
String signle_multi_lines = '''
signle
multi lines
multi lines string
''';
print("signle_multi_lines = ${signle_multi_lines}");
String double_multi_lines = """
double
multi lines
multi lines string
""";
print("double_multi_lines = ${double_multi_lines}");
String backslash_n = "string line1\nstring line2\nstring line3";
print("backslash_n = ${backslash_n}");
String raw_string = r"string line1\nstring line2\nstring line3";
print("raw_string = ${raw_string}");
}
```
String str = 'hello'; 单引号或双引号为单行 三引号为多行
\n为换行 前置加r表示不转义 字符转后乘以整数为复制次数
可直接用中括号字符转中的值类似数组
运算符 + * == []
插值表达式 ${expression}
常用属性 length isEmpty(是否为空) isNotEmpty(是否不为空)
常用方法 contains() 是否包含, subString() 截取(0,n), startWidth() 是否以xx开头, endsWidtj() 是否xx结尾, indexOf(), lastIndexOf(), toLowerCase(), toUpperCase(), trim(), trimLeft(), trimRight(), split(), replaceXX()
字符串 关键字String
1、使用单引号、双引号创建字符串
2、使用三个引号或双引号创建多行字符串
3、使用r创建原始raw字符串, 在字符串前面加上r,若字符串包含转义字符会把转义字符失效,原本字符打印显示出来。
字符串操作
1、运算符:+ 拼接 字符串、* int 重复打印字符串的次数、==比较两个字符串是否相等、[]取字符串某个索引下的值
2、插值表达式:${expression}
int a = 1;
int b = 2;
print("a+b= ${a+b}");
print("a = $a");常用属性有:
length、isEmpty、isNotEmpty
注意:空格代表是有值的
常用方法有:
contains()判断是包含某字符串、subString()截取开始索引到结束索引这段得字符串、toLowerCase()转换成小写、toUpperCase()转换成大写、
startsWith()判断是否以某个字符串开始、endsWith()判断是否以某个字符串结束、trim()取消左右空格、trimLeft()、trimRight()、
indexOf()取字符串中某个字符的索引、lastIndexOf()跟indexOf一样,不一样的是倒着开始找、split()以某个字符分割、replaceXXX()新旧字符替换
字符串常用方法
字符串操作
字符串创建
字符串常用方法
插值表达式
字符串常用的操作符
字符串创建的方式
字符串中插值表达式${expression}
r 声明原始raw字符串,即字符串中的\n之类的字符被直接输出
字符串创建
使用单引号,双引号创建字符串
使用三个引号或双引号创建多行字符串
使用r创建原始raw字符串(不进行转义
字符串操作
运算符:+、*、==、[]
插值表达式:${expression}
常用属性:length、isEmpty、isNotEmpty
常用方法
contains(), subString()
startsWith(), endsWith()
indexOf(), lastIndexOf()
toLowerCase(), toUpperCase()
trim(), trimLeft(), trimRight()
split(), replaceXXX()
String str1='hello dart';//""
String str2='''hello
dart''';//""" 多行显示
print(str2);
String str3= "hello \n dart"; //换行显示
String str4= "hello \n dart"; //不换行显示(使用r创建原始raw字符串)
print(str3);
print(str4);
//运算
String str5='this is my ';
print(str5+"dart");
print(str5*5);//复制五次
print(str5==str3);//两个字符串是否相等
print(str5[0]);
int aa=1;
int bb=3;
print("aa+bb=${aa+bb}");//插值表达式
字符串*n,表示字符串重复n次
字符串[0],表示取第0位
插值表达式:${expression}