当前位置:网站首页>[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
边栏推荐
- Target detection - make your own deep learning target detection data set with labelimg
- Armv8-a programming guide MMU (4)
- What is Amazon keyword index? The consequences of not indexing are serious
- 隐藏在 Nebula Graph 背后的星辰大海
- Boot 事务使用
- /Bin/ld: cannot find -llz4
- 【5G NR】RRC连接释放
- Aike AI frontier promotion (7.2)
- Practice of constructing ten billion relationship knowledge map based on Nebula graph
- Nebula Graph & 数仓血缘关系数据的存储与读写
猜你喜欢

Postgressql stream replication active / standby switchover primary database no read / write downtime scenario

Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit

Remove the underline in router link

通过两级网关设计来路由服务网格流量

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

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

解决** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the defau

【5G NR】RRC连接释放

Crawl the information of national colleges and universities in 1 minute and make it into a large screen for visualization!

Traversal before, during and after binary tree
随机推荐
手机app通达信添加自定义公式(分时T+0)为例子讲解
What are the necessary functions of short video app development?
Idea jar package conflict troubleshooting
潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
Data Lake (11): Iceberg table data organization and query
可视化技术在 Nebula Graph 中的应用
Vscade set multi line display of tab
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
[fluent] dart language (DART language features | JIT instant compilation | AOT static compilation)
[5g NR] RRC connection release
2020.4.12 byte written test questions B DP D monotone stack
又是一年毕业季
Add an empty column to spark dataframe - add an empty column to spark dataframe
How to use percona tool to add fields to MySQL table after interruption
Set the background picture in the idea (ultra detailed)
Group by的用法
[Xiaobai chat cloud] suggestions on container transformation of small and medium-sized enterprises
win10系统升级一段时间后,内存占用过高
[idea] recommend an idea translation plug-in: translation "suggestions collection"
注册成为harmonyos开发者并安装DevEco Studio 3.0 Beta2 for HarmonyOS