我有这个字符串
List<String> params = ['A','B','C'];
我想把它转换成"['A']['B']['C']"我该如何正确地转换它?
"['A']['B']['C']"
6ojccjat1#
您可以尝试:
void main(){ List<String> params = ['A','B','C']; final out = params.map((e) => "['$e']").join(); print(out); }
图纸:
['A']['B']['C']
zhte4eai2#
你能做到的
List<String> params = ['A','B','C']; List newParams = []; for(var item in params){ newParams.add([item]); } String stringParams = newParams.toString(); String noBracketParams = stringParams.substring( 1, stringParams.length - 1 ); String noCommasParams = noBracketParams.replaceAll(',', ''); print(noCommasParams);
olqngx593#
List<String> params = ['A', 'B', 'C']; List.generate( params.length, (index) => params[index] = '''['${params[index]}']'''); var str = ''; params.forEach((item) => str += item); print(str);
3条答案
按热度按时间6ojccjat1#
您可以尝试:
图纸:
zhte4eai2#
你能做到的
olqngx593#