zandose
zandose
CC#
Created by zandose on 3/15/2023 in #help
❔ I'm trying to convert a Vector3 string to a Vector3 but the numbers returned aren't correct.
// Converts a string to a Vector3.
// Examples: 's' can be ".5,.5,.5" or "1".
public Vector3 ConvertStringToVector3(string s)
{

string StringToConvert = s;
StringToConvert.Split(',');
StringToConvert.Select(part => float.Parse(StringToConvert));
StringToConvert.ToArray();

Debug.Log("xyz = s::" + StringToConvert);
Debug.Log("xyz.Split(',')::" + StringToConvert); // Returns .5
Debug.Log("xyz.Select(part => float.Parse(xyz))::" + StringToConvert); // Returns .5
Debug.Log("xyz.ToArray()::" + StringToConvert); // Returns .5

Vector3 vector3;

if (StringToConvert.Length == 1) // If the string 's' is only using one number instead of three, like "1".
{
//float[] xyzf = new float[] { float.Parse(xyz[0], System.Globalization.CultureInfo.InvariantCulture) };
Debug.Log("xyz[0]::" + StringToConvert[0]);
vector3 = new Vector3(StringToConvert[0], StringToConvert[0], StringToConvert[0]);
Debug.Log("vector3::" + vector3); // The number that comes out is not "1"
}
else // If the string 's' is three numbers, like ".5,.5,.5".
{
Debug.Log("xyz[0]::" + StringToConvert[0]);
Debug.Log("xyz[1]::" + StringToConvert[1]);
Debug.Log("xyz[2]::" + StringToConvert[2]);
vector3 = new Vector3(StringToConvert[0], StringToConvert[1], StringToConvert[2]);
Debug.Log("vector3::" + vector3); // The number that comes out is not ".5"
}

return vector3;
}
// Converts a string to a Vector3.
// Examples: 's' can be ".5,.5,.5" or "1".
public Vector3 ConvertStringToVector3(string s)
{

string StringToConvert = s;
StringToConvert.Split(',');
StringToConvert.Select(part => float.Parse(StringToConvert));
StringToConvert.ToArray();

Debug.Log("xyz = s::" + StringToConvert);
Debug.Log("xyz.Split(',')::" + StringToConvert); // Returns .5
Debug.Log("xyz.Select(part => float.Parse(xyz))::" + StringToConvert); // Returns .5
Debug.Log("xyz.ToArray()::" + StringToConvert); // Returns .5

Vector3 vector3;

if (StringToConvert.Length == 1) // If the string 's' is only using one number instead of three, like "1".
{
//float[] xyzf = new float[] { float.Parse(xyz[0], System.Globalization.CultureInfo.InvariantCulture) };
Debug.Log("xyz[0]::" + StringToConvert[0]);
vector3 = new Vector3(StringToConvert[0], StringToConvert[0], StringToConvert[0]);
Debug.Log("vector3::" + vector3); // The number that comes out is not "1"
}
else // If the string 's' is three numbers, like ".5,.5,.5".
{
Debug.Log("xyz[0]::" + StringToConvert[0]);
Debug.Log("xyz[1]::" + StringToConvert[1]);
Debug.Log("xyz[2]::" + StringToConvert[2]);
vector3 = new Vector3(StringToConvert[0], StringToConvert[1], StringToConvert[2]);
Debug.Log("vector3::" + vector3); // The number that comes out is not ".5"
}

return vector3;
}
11 replies
CC#
Created by zandose on 12/8/2022 in #help
❔ HTTP code not returning expected result.
So I have the following code
FormUrlEncodedContent content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("Test1", "Test2") });
Task<HttpResponseMessage> result = client.PostAsync(URL, content);
Task<string> resultContent = result.Result.Content.ReadAsStringAsync();
Debug.Log(resultContent.Result);
FormUrlEncodedContent content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("Test1", "Test2") });
Task<HttpResponseMessage> result = client.PostAsync(URL, content);
Task<string> resultContent = result.Result.Content.ReadAsStringAsync();
Debug.Log(resultContent.Result);
Which should send the following http://zandose1.centralus.cloudapp.azure.com/test.php?Test1=Test2 and then I have some PHP code which should return Test1=Test2. If I put http://zandose1.centralus.cloudapp.azure.com/test.php?Test1=Test2 into a browser it works fine but with the C# code it doesn't get the anything.
26 replies