Hampus Ramsten
Hampus Ramsten

Reputation: 41

Make mutiple single-line strings shortcut Flutter

I'm just wondering if there is any shortcut to making multiple lines into separate strings. I was making a list and copied in data from worldtimeapi.com, in the format:

List<list_Of_Places> placeList = ["""
  Africa/Abidjan
  Africa/Accra
  Africa/Algiers
  Africa/Bissau
  Africa/Cairo
  Africa/Casablanca
  Africa/Ceuta
  Africa/El_Aaiun
"""];

And now I want to make these into separate strings. I was wondering if there is any shortcut to this or will I have to put '...' on every line? Like this:

List<list_Of_Places> placeList = [
  'Africa/Abidjan'
  'Africa/Accra'
  'Africa/Algiers'
  'Africa/Bissau'
  'Africa/Cairo'
  'Africa/Casablanca'
  'Africa/Ceuta'
  'Africa/El_Aaiun'
];

Sorry if my formating is bad, this is my first post here.

Upvotes: 3

Views: 249

Answers (2)

Jigar Patel
Jigar Patel

Reputation: 5423

If you don't want to do it programmatically, you can use your IDE's Replace-All functionality with your copied text in a new file to replace each <new-line> character with ',<new-line>' like this..

enter image description here

which will give you this on replacing-all

enter image description here

and lastly you can add 2 single quotes manually, one at the start and one at the end.

Upvotes: 0

JideGuru
JideGuru

Reputation: 7660

You can use split on the list String. like this

List<String> placeList = ["""
  Africa/Abidjan
  Africa/Accra
  Africa/Algiers
  Africa/Bissau
  Africa/Cairo
  Africa/Casablanca
  Africa/Ceuta
  Africa/El_Aaiun
"""];
List seperatedPlaceList = placeList[0].trim().split('\n'); // split by line break
print(seperatedPlaceList);

Upvotes: 1

Related Questions