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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With