如何在Dart中连接两个字符串? [英] How to concatenate two string in Dart?

查看:1951
本文介绍了如何在Dart中连接两个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Dart编程语言的新手,任何人都可以帮助我找到Dart中可用的最佳字符串连接方法。

I am new to Dart programming language and anyone help me find the best string concatenation methods available in Dart.

我只找到加号(+)进行连接像其他编程语言一样的字符串。

I only found the plus (+) operator to concatenate strings like other programming languages.

推荐答案

有3种方法来连接字符串

There are 3 ways to concatenate strings

String a = 'a';
String b = 'b';

var c1 = a + b; // + operator
var c2 = '$a$b'; // string interpolation
var c3 = 'a' 'b'; // string literals separated only by whitespace are concatenated automatically
var c4 = 'abcdefgh abcdefgh abcdefgh abcdefgh' 
         'abcdefgh abcdefgh abcdefgh abcdefgh';

通常,字符串插入法优于 +

Usually string interpolation is preferred over the + operator.

还有 StringBuffer 用于更复杂,更高效的字符串构建。

There is also StringBuffer for more complex and performant string building.

这篇关于如何在Dart中连接两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆