papsphilip
2019年6月28日 12:41:19
I need some help with some vex code. I have a sequence of strings that i want to convert to pairs of xy. see the image attached. every string (float) is separated with a blank space so i need to somehow get a pair of two strings each time and put them in a vector as X Y Coordinates. I am still very new to vex and i have no idea how to approach this, i only know there is a function to convert string to float but thats about it.
tamte
2019年6月28日 12:58:56
Attrib Wrangle in Detail mode
string raw = "1.1 1.2 2.1 2.2 3.1 3.2 4.1 4.2";
string coords[] = split(raw);
for (int i=0; i<len(coords); i+=2){
vector P = 0;
P.x = atof(coords[i]);
P.y = atof(coords[i+1]);
addpoint(0, P);
}
papsphilip
2019年6月28日 17:42:51
tamte
Attrib Wrangle in Detail mode
string raw = "1.1 1.2 2.1 2.2 3.1 3.2 4.1 4.2";
string coords[] = split(raw);
for (int i=0; i<len(coords); i+=2){
vector P = 0;
P.x = atof(coords[i]);
P.y = atof(coords[i+1]);
addpoint(0, P);
}
yes! thank you it worked, i had to put the wrangle in a foreach loop to do the same for every point string attribute. This would not be needed if there was a way to import shapefiles though
tamte
2019年6月28日 17:44:11
instead of putting it into the for each loop, just use Point Wrangle