当前位置:网站首页>[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
边栏推荐
猜你喜欢
【5G NR】RRC连接释放
Write your own CPU Chapter 11 - learning notes
Compress words (kmp/ string hash, double hash)
Maui learning road (III) -- in depth discussion of winui3
请问怎么在oracle视图中使用stustr函数
Recommended practice sharing of Zhilian recruitment based on Nebula graph
Application of visualization technology in Nebula graph
《大学“电路分析基础”课程实验合集.实验六》丨典型信号的观察与测量
mysql 计算经纬度范围内的数据
Set the background picture in the idea (ultra detailed)
随机推荐
理想之光不灭
关于mysql安装的一些问题
/Bin/ld: cannot find -lssl
注册成为harmonyos开发者并安装DevEco Studio 3.0 Beta2 for HarmonyOS
[Xiaobai chat cloud] suggestions on container transformation of small and medium-sized enterprises
HMS core machine learning service helps zaful users to shop conveniently
(practice C language every day) the sum of the nearest three numbers
Boot 事务使用
Moveit obstacle avoidance path planning demo
IDEA中设置背景图片(超详细)
Vscade set multi line display of tab
如何實現十億級離線 CSV 導入 Nebula Graph
处理gzip: stdin: not in gzip formattar: Child returned status 1tar: Error is not recoverable: exitin
Make p12 certificate [easy to understand]
Floyed "suggestions collection"
Song of cactus - throwing stones to ask the way (2)
Xpt2046 four wire resistive touch screen
Pyobject to char* (string)
Register as a harmonios developer and install deveco studio 3.0 beta2 for harmonios
The outline dimension function application of small motherboard