簡體   English   中英

如何在dart中為變量添加引號

[英]How to add a Quotation mark to a variable in dart

我在 flutter 中聲明了一個變量,我想將它打印為字符串,並在其周圍加上引號,如下所示:

String name = "samuel";

so when I print it out I would get double quotations around it


"Samuel"

我試過

 print("'" + name +"'")

print('"' + name + '"')

print("\"" + name + "\"")

但沒有一個工作。 請問,我怎樣才能在飛鏢中實現這一目標?

您可以使用

  • 不同的外引號
print('"$name"')
print("'$name'") // prints ' quotes
  • 轉義引號
print('\"$name\"')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM