当前位置:网站首页>[fluent] dart data type string type (string definition | string splicing | string API call)
[fluent] dart data type string type (string definition | string splicing | string API call)
2022-07-02 16:10:00 【Programmer community】
List of articles
- I . String definition
- I . String splicing
- III . character string API call
- IV . character string Demo Example
I . String definition
Use single quotes ’ ’ and Double quotes " " You can define strings ;
// String definition : You can use either single quotation marks , You can also use double quotes String str_1 = ' Single quotation marks define the string ';String str_2 = " Double quotation marks define the string ";I . String splicing
1 . Use “$” String splicing : In a single quotation mark or double quotation mark string , Use $ Variable name The way , You can splice the contents represented by the variable name into a string ;
String str_3 = "str_1 : $str_1 str_2 : $str_2";// Use $ String concatenation : str_1 : Single quotation marks define the string str_2 : Double quotation marks define the string print(" Use \$ String concatenation : " + str_3);2 . Use “+” Operator : Use + Operator You can concatenate strings , This method is similar to Java similar ;
String str_4 = "str_1 : " + str_1 + " , str_2 : " + str_2;// Print the results : Use + String concatenation : str_1 : Single quotation marks define the string , str_2 : Double quotation marks define the string print(" Use + String concatenation : " + str_4);3 . Use ${ expression } The way :${ expression } , Can be expression The content is spliced into a string ;
String add = "1 + 2 = ${1 + 2}";// Print the results : Use ${} String concatenation : 1 + 2 = 3print(" Use \${} String concatenation : " + add);III . character string API call
1 . String character string API file : https://api.dart.dev/stable/2.7.1/dart-core/String-class.html
2 . String interception : Start position needs to be specified ( contain ) And end position ( It doesn't contain ) , from 0 Start counting ; If only the starting position , Then it will be intercepted directly to the end ;
String str_substring = str_1.substring(3, 6);// Print the results : String interception : Definition words print(" String interception : " + str_substring);3 . Get string index :
// Pass in the substring in the parameter , Or regular expressions int index = str_1.indexOf(" set ");// Print the results : index : 3print("index : $index");IV . character string Demo Example
1 . Code example :
import 'package:flutter/material.dart';class DartType_String extends StatefulWidget {
@override _DartType_StringState createState() => _DartType_StringState();}class _DartType_StringState extends State<DartType_String> {
@override Widget build(BuildContext context) {
stringDemo(); return Container(child: Text(' String type ')); } // String type Example stringDemo(){
// I . String definition // String definition : You can use either single quotation marks , You can also use double quotes String str_1 = ' Single quotation marks define the string '; String str_2 = " Double quotation marks define the string "; // II . String splicing // 1 . String splicing 1 : $ String splicing : In a single quotation mark or double quotation mark string , Use $ Variable name The way , // You can splice the contents represented by the variable name into a string String str_3 = "str_1 : $str_1 str_2 : $str_2"; // Use $ String concatenation : str_1 : Single quotation marks define the string str_2 : Double quotation marks define the string print(" Use \$ String concatenation : " + str_3); // 2 . String splicing 2 : Use "+" Operator , You can concatenate strings , This method is similar to Java similar String str_4 = "str_1 : " + str_1 + " , str_2 : " + str_2; // Print the results : Use + String concatenation : str_1 : Single quotation marks define the string , str_2 : Double quotation marks define the string print(" Use + String concatenation : " + str_4); // 3 . String splicing 3 : Use ${ expression } , You can splice the contents of an expression into a string String add = "1 + 2 = ${1 + 2}"; // Print the results : Use ${} String concatenation : 1 + 2 = 3 print(" Use \${} String concatenation : " + add); // III . Commonly used strings API // 1 . String interception // Start position needs to be specified ( contain ) And end position ( It doesn't contain ) , from 0 Start counting // If only the starting position , Then it will be intercepted directly to the end String str_substring = str_1.substring(3, 6); // Print the results : String interception : Definition words print(" String interception : " + str_substring); // 2 . Get string index // Pass in the substring in the parameter , Or regular expressions int index = str_1.indexOf(" set "); // Print the results : index : 3 print("index : $index"); }}2 . Execution results :
Use $ String concatenation : str_1 : Single quotation marks define the string str_2 : Double quotation marks define the string use + String concatenation : str_1 : Single quotation marks define the string , str_2 : Double quotation marks define the string use ${
} String concatenation : 1 + 2 = 3 String interception : Definition words index : 3
边栏推荐
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
- Review materials for the special topic of analog electronics with all essence: basic amplification circuit knowledge points
- 理想之光不灭
- 解决** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the defau
- 关于mysql安装的一些问题
- beforeEach
- 华为云服务器安装mysqlb for mysqld.service failed because the control process exited with error code.See “sys
- /Bin/ld: cannot find -lxml2
- Best practices for building multi architecture images
- Aiko ai Frontier promotion (7.2)
猜你喜欢

Practice of constructing ten billion relationship knowledge map based on Nebula graph

JS learning notes - process control

2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题

Summary of multithreading and thread synchronization knowledge

Ant group's large-scale map computing system tugraph passed the national evaluation

理想之光不灭

图数据库|Nebula Graph v3.1.0 性能报告

Compress words (kmp/ string hash, double hash)

愛可可AI前沿推介(7.2)

手机app通达信添加自定义公式(分时T+0)为例子讲解
随机推荐
Song of cactus - throwing stones to ask the way (3)
关于mysql安装的一些问题
注册成为harmonyos开发者并安装DevEco Studio 3.0 Beta2 for HarmonyOS
构建多架构镜像的最佳实践
Maui learning road (III) -- in depth discussion of winui3
(practice C language every day) the sum of the nearest three numbers
Vscade set multi line display of tab
Strings and arrays
Register as a harmonios developer and install deveco studio 3.0 beta2 for harmonios
/Bin/ld: cannot find -lxml2
Solve * * warning * *: your ApplicationContext is unlikely to start due to a @componentscan of the defau
Multi data source configuration code
After the win10 system is upgraded for a period of time, the memory occupation is too high
SQL modification statement
Maui学习之路(三)--Winui3深入探讨
Crawl the information of national colleges and universities in 1 minute and make it into a large screen for visualization!
Set the background picture in the idea (ultra detailed)
Comprehensively interpret the background and concept of service mesh
Data Lake (11): Iceberg table data organization and query
Armv8-a programming guide MMU (4)