当前位置:网站首页>[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
边栏推荐
- Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
- 基于 Nebula Graph 构建百亿关系知识图谱实践
- End time processing method of wechat v3native payment settings
- Song of cactus - throwing stones to ask the way (2)
- SQL modification statement
- Teach you how to build virtual machines locally and deploy microservices
- 解决** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the defau
- Boot transaction usage
- Make p12 certificate [easy to understand]
- Wise target detection 23 - pytoch builds SSD target detection platform
猜你喜欢

dried food! Understand the structural vulnerability of graph convolution networks

Tree binary search tree

潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)

HMS core machine learning service helps zaful users to shop conveniently

注册成为harmonyos开发者并安装DevEco Studio 3.0 Beta2 for HarmonyOS

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

Recommended practice sharing of Zhilian recruitment based on Nebula graph

Compress words (kmp/ string hash, double hash)

JS learning notes - variables

mysql min() 求某条件下最小的值出现多个结果
随机推荐
Construction and business practice of Zhongke brain knowledge map platform
Group by的用法
原神2.6服务端下载以及搭建安装教程
AWS virtual machine expansion
Multi data source configuration code
After the win10 system is upgraded for a period of time, the memory occupation is too high
[solution] educational codeforces round 82
Boot connection to impala database
SQL modification statement
纪念成为首个 DAYU200 三方 demo 贡献者
Conditions and solutions of deadlock
智联招聘的基于 Nebula Graph 的推荐实践分享
基于 Nebula Graph 构建百亿关系知识图谱实践
(Wanzi essence knowledge summary) basic knowledge of shell script programming
Leetcode -- number of palindromes
Pattern matching extraction of specific subgraphs in graphx graph Computing Practice
Memory alignment of structure
Tree binary search tree
IDEA中设置背景图片(超详细)
What is Amazon keyword index? The consequences of not indexing are serious