簡體   English   中英

Flutter 將 int 變量轉換為字符串

[英]Flutter convert int variable to string

我是 Flutter 的新手,我想知道(對我來說)找到如何轉換我的變量 var int counter = 0; 的解決方案有多困難; 變成一個變量 var String $counter = "0";

我搜索了很多,但更多的是我只找到了類似 var myInt = int.parse('12345'); 的東西。

這不適用於 var myInt = int.parse(counter);

使用toString和/或toRadixString

  int intValue = 1;
  String stringValue = intValue.toString();
  String hexValue = intValue.toRadixString(16);

或者,如評論中所述

  String anotherValue = 'the value is $intValue';

// 字符串轉int

String s = "45";
int i = int.parse(s);

// 整數轉字符串

int j = 45;
String t = "$j";

// 如果后者看起來很奇怪,請查看https://dart.dev 上的字符串插值

您可以在 int 類中使用 .toString() 函數。

int age = 23;
String tempAge = age.toString();

那么你可以簡單地將整數轉換為字符串。

int i=10;
String st = i.toString(); // Converted to String

暫無
暫無

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

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