I am completing a List with data returned from an XML API.
I am now gain the data in the format I require and have the function to put those var's into a list as follows
List data = [
"Line:", pln,
"\n\nLat:", lat,
"\n\nLong:", long,
];
It prints like
[Line:, P1,
Lat:, x.xxxxx,
Long:, x.xxxxx]
The characters necessary to construct my List such as [] and ,are not wanted in the final print and I can't get rid of them.
I only want the characters within the quotemarks, such as from [Line:, P1, I just want Line: value, but without the other characters the List function won't work.
Thank you
Update
It is used as metadata and added to a map marker, which expands a pop-up upon clicking and shows this data as a list with \n\n adding a new line break
metadata.setString("key_poi", data.toString());
mapScene.addMapMarker(mapMarker);
CodePudding user response:
You don't provide the code, but I guess you're doing this:
print(data);
data is a list, so it's printing the list.
What you probably want to do is convert the list to a String - by joining each element of the list to the other. There's a function for that - join - so try this:
print(data.join());
Note join can take a separator argument - and you can probably use it to get rid of those ugly \n's you have in your code.
In fact, I'd probably do this instead:
List data = [
"Line: $pln",
"Lat: $lat",
"Long: $long",
];
print(data.join("\n\n"));
