Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. public static string GetVectorComponentFromVector(string vector, int position)
  2. {
  3. string temp = vector;
  4. temp = temp.TrimStart(null); //remove whitespace
  5. if (position == 0)
  6. {
  7. int length = vector.IndexOf(",");
  8. if (length != -1)
  9. {
  10. return vector.Substring(0, length);
  11. }
  12. return vector;
  13. }
  14. if (position == 1)
  15. {
  16. string subtemp = TrimVectorComponent(temp);
  17. int length = subtemp.IndexOf(",");
  18. if (length != -1)
  19. {
  20. return subtemp.Substring(0, length);
  21. }
  22. return subtemp;
  23. }
  24. if (position == 2)
  25. {
  26. string subtemp = TrimVectorComponent(temp);
  27. subtemp = TrimVectorComponent(subtemp);
  28. int length = subtemp.IndexOf(",");
  29. if (length != -1)
  30. {
  31. return subtemp.Substring(0, length);
  32. }
  33. return subtemp;
  34. }
  35. if (position == 3)
  36. {
  37. string subtemp = TrimVectorComponent(temp);
  38. subtemp = TrimVectorComponent(subtemp);
  39. return TrimVectorComponent(subtemp);
  40. }
  41.  
  42. throw new FormatException("Only vector4 is supported");
  43. }
  44.  
  45. public static string TrimVectorComponent(string vector)
  46. {
  47. char[] trimChars = { '+', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.' };
  48. string subtemp = vector.TrimStart(trimChars);
  49. char[] trimComma = { ',' };
  50. return subtemp.TrimStart(trimComma).TrimStart(null);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement