Home > Enterprise >  How to remove Square brackets from output in dart language?
How to remove Square brackets from output in dart language?

Time:10-19

The following output give me C:/src/flutter/bin/cache/dart-sdk/bin/dart.exe --enable-asserts C:\Users\Mian\IdeaProjects\FirstWork\prac.dart [your, halako, dsfds, mian, khan, sami]

enter image description here

CodePudding user response:

please try with this

void main() {
  var list = ["test", "test1"];
  String list1 = getWithoutBracket(list);
  print(list1);
}

String getWithoutBracket(var list) {
  String digit = "";

  if (list != null && list.isNotEmpty) {
    list.asMap().forEach((index, element) {
      digit  = element;

      if (index != list.length - 1) {
        digit  = ", ";
      }
    });
  }
  return digit;
}

output: test, test1

CodePudding user response:

you can use join() function to get your desired output

you can try this code :

void main() {

var lst = new List(3); 
  for (int i = 0; i < 3; i  ) {
lst[i] = i;
}


print(lst.join(", "));
} 

the original answer

Edit:

in your case Just replace the print with this and its work fine :

print(digit.join(", "));
  • Related