skip to Main Content

I have this String

List<String> params = ['A','B','C'];

I want to convert this to "['A']['B']['C']"
How can I convert this properly?

3

Answers


    • I’m not sure what you’re trying to do, but it can be achieved like this
        List<String> params = ['A', 'B', 'C'];
        List.generate(
            params.length, (index) => params[index] = '''['${params[index]}']''');
        var str = '';
        params.forEach((item) => str += item);
        print(str);
    
    Login or Signup to reply.
  1. you can do this

      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);
    
    Login or Signup to reply.
  2. You can try:

    void main(){
      List<String> params = ['A','B','C'];
      final out = params.map((e) => "['$e']").join();
      print(out);
    }
    

    Prints:

    ['A']['B']['C']
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search