Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetVectorComponentFromVector(string vector, int position)
- {
- string temp = vector;
- temp = temp.TrimStart(null); //remove whitespace
- if (position == 0)
- {
- int length = vector.IndexOf(",");
- if (length != -1)
- {
- return vector.Substring(0, length);
- }
- return vector;
- }
- if (position == 1)
- {
- string subtemp = TrimVectorComponent(temp);
- int length = subtemp.IndexOf(",");
- if (length != -1)
- {
- return subtemp.Substring(0, length);
- }
- return subtemp;
- }
- if (position == 2)
- {
- string subtemp = TrimVectorComponent(temp);
- subtemp = TrimVectorComponent(subtemp);
- int length = subtemp.IndexOf(",");
- if (length != -1)
- {
- return subtemp.Substring(0, length);
- }
- return subtemp;
- }
- if (position == 3)
- {
- string subtemp = TrimVectorComponent(temp);
- subtemp = TrimVectorComponent(subtemp);
- return TrimVectorComponent(subtemp);
- }
- throw new FormatException("Only vector4 is supported");
- }
- public static string TrimVectorComponent(string vector)
- {
- char[] trimChars = { '+', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.' };
- string subtemp = vector.TrimStart(trimChars);
- char[] trimComma = { ',' };
- return subtemp.TrimStart(trimComma).TrimStart(null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement