here is my data which is in a text file. These data are coordinates.
(55, 297)(300, 297)(55, 297)(55, 52)
I read these data points by the bellow code,
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (System.IO.StreamReader sr = new System.IO.StreamReader("C:\\Users\\UVINDU\\Desktop\\Data.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string splits = line.TrimStart('[');
string[] split = line.Split(')');
string a = split[0], b = split[1], c = split[2], d = split[3];
a = a.Trim(new Char[] { '[', '(' });
Console.WriteLine(a);
b = b.Trim(new Char[] { ',', '(' });
Console.WriteLine(b);
c = c.Trim(new Char[] { ',', '(' });
Console.WriteLine(c);
d = d.Trim(new Char[] { ',', '(' });
Console.WriteLine(d);
Console.ReadLine();
}
}
}
}
}
how can I add these values(a,b,c,d) to a Vector3 array?
So, basicly you want a parse string to float:
string s = "55";
string s2 = "297";
string s3 = "0";
float x = float.Parse(s);
float y = float.Parse(s2);
float z = float.Parse(s3);
Then you want to create Vector3 object:
Vector3 v1 = new Vector3(x, y, z);
Vector3 v2 = new Vector3(x2, y2, z2);
Vector3 v3 = new Vector3(x3, y3, z3);
Vector3 v4 = new Vector3(x4, y4, z4);
And finally you want to add this vector to array:
Vector3[] vArr = new Vector3[4] {v1, v2, v3, v4};
But frankly speaking I am not sure what the values you showed represent, and why there is missing third value for z.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.