I have an array of strings, they contain information about objects position in 3D space.The positions are separated with commas. The first one before the comma is x position, second one is y and third one is z. Some of these strings are:
string a = "0.95,2.34,0" string b = "18.05,5,0" string c ="112.1,10,3"
I want to assign 0.95 into float xPos, 2.34 into yPos, 0 into zPos etc.
I want to do these one by one in a for loop for every string in the array.
I couldn’t use substr because they have different lengths.
How can i get the substrings between the commas and put them into variables?
-I use c++
P.S sorry for my bad English
Usually there is a
Split()type of method in most languages. You would call the method on the incoming string, and split it on the comma then you would have a resulting array with two strings, one of each value. Place the first value in X and the second in Y. You might want a helper method to do this.