0

I have a list. I want to convert this list to String data. I try to convert like this below, but brackets [] could not delete. My List datas: [6, 8, 9, 11, 14, 15, 16, 133, 134, 135, 136, 138] I tried like this to convert.

List value = [6, 8, 9, 11, 14, 15, 16, 133, 134, 135, 136, 138]
data = value.toString();

My data Output like:

print(data);
[6, 8, 9, 11, 14, 15, 16, 133, 134, 135, 136, 138]

But it doesn't work. How can I convert this list to string without []. Thanks.

0

3 Answers 3

3

I would suggest using join

https://api.dart.dev/stable/2.10.4/dart-core/Iterable/join.html

List value = [6, 8, 9, 11, 14, 15, 16, 133, 134, 135, 136, 138]
var data = value.join(',')
Sign up to request clarification or add additional context in comments.

Comments

0

Try:

List<int> value = [6, 8, 9, 11, 14, 15, 16, 133, 134, 135, 136, 138]; 
  
List<String> string_values = value.map((value) => value.toString()).toList();

Comments

0
void main() {
  String output='';
  List value = [6, 8, 9, 11, 14, 15, 16, 133, 134, 135, 136, 138];
  value.forEach((x)=>x.toString());
  output = value.join(',');
  print(output);
}

3 Comments

While this code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users learn, and apply that knowledge to their own code. You are also likely to have positive feedback from users in the form of upvotes, when the code is explained.
Thanks Amit. Since this is my first answer I wasn't sure what the best way to share would be. I'll definitely iterate :)
Yes pls, explaining it to some extent, would be a lot meaningful. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.