当前位置:网站首页>[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
边栏推荐
- Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface
- /Bin/ld: cannot find -lxslt
- Nebula Graph & 数仓血缘关系数据的存储与读写
- Effectively use keywords to increase Amazon sales
- Application of visualization technology in Nebula graph
- Pyobject to char* (string)
- Armv8-a programming guide MMU (4)
- Write your own CPU Chapter 11 - learning notes
- Moveit obstacle avoidance path planning demo
- [Xiaobai chat cloud] suggestions on container transformation of small and medium-sized enterprises
猜你喜欢

Memory alignment of structure

Traversal before, during and after binary tree

可视化技术在 Nebula Graph 中的应用

Pattern matching extraction of specific subgraphs in graphx graph Computing Practice

Route service grid traffic through two-level gateway design

Pandora IOT development board learning (RT thread) - Experiment 2 RGB LED experiment (learning notes)

The sea of stars hidden behind the nebula graph

华为云服务器安装mysqlb for mysqld.service failed because the control process exited with error code.See “sys

Introduction to Dynamic Planning II (5.647.62)

Review materials for the special topic of analog electronics with all essence: basic amplification circuit knowledge points
随机推荐
基于 Nebula Graph 构建百亿关系知识图谱实践
仙人掌之歌——投石问路(2)
【5G NR】RRC连接释放
mysql 计算经纬度范围内的数据
Boot 连接 Impala数据库
Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface
/Bin/ld: cannot find -llz4
(practice C language every day) the sum of the nearest three numbers
Compress words (kmp/ string hash, double hash)
Floyed "suggestions collection"
Postgressql stream replication active / standby switchover primary database no read / write downtime scenario
Vscode设置标签页多行显示
Boot transaction usage
去除router-link中的下划线
The light of ideal never dies
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
Multi data source configuration code
数仓中的维度表与事实表
Data Lake (11): Iceberg table data organization and query
Armv8-a programming guide MMU (4)