Advertisement
Guest User

Untitled

a guest
Jan 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. function [ output] = dasher( string )
  2.  
  3. letters = "qwertyuiopasdfghjklzxcvbnm";
  4. numbers = "1234567890";
  5.  
  6. numbercount = 0;
  7. lettercount = 0;
  8. plate = '';
  9. i = 1;
  10. while i < length(string)
  11. if (contains(numbers,string(i)))
  12. lettercount = 0;
  13. j = 1;
  14. numbercount = numbercount + 1;
  15. while(j+i < length(string) + 1 && contains(numbers,string(i+j)))
  16. j = j + 1;
  17. numbercount = numbercount + 1;
  18. end
  19. if (numbercount == 2)
  20. plate(length(plate) + 1) = string(i);
  21. plate(length(plate) + 1) = string(i + 1);
  22. plate(length(plate) + 1) = '-';
  23. i = i + 2;
  24. end
  25. if (numbercount == 1)
  26. plate(length(plate) + 1) = string(i);
  27. plate(length(plate) + 1) = '-';
  28. i = i + 1;
  29. end
  30. elseif (contains(letters,string(i)))
  31. numbercount = 0;
  32. j = 1;
  33. lettercount = lettercount + 1;
  34. while(j+i < length(string) + 1 && contains(letters,string(i+j)))
  35. j = j + 1;
  36. lettercount = lettercount + 1;
  37. end
  38. if (lettercount == 2)
  39. plate(length(plate) + 1) = string(i);
  40. plate(length(plate) + 1) = string(i + 1);
  41. plate(length(plate) + 1) = '-';
  42. i = i + 2;
  43. end
  44. if (lettercount == 3)
  45. plate(length(plate) + 1) = string(i);
  46. plate(length(plate) + 1) = string(i + 1);
  47. plate(length(plate) + 1) = string(i + 2);
  48. plate(length(plate) + 1) = '-';
  49. i = i + 3;
  50. end
  51. if (lettercount == 4)
  52. plate(length(plate) + 1) = string(i);
  53. plate(length(plate) + 1) = string(i+1);
  54. plate(length(plate) + 1) = '-';
  55. plate(length(plate) + 1) = string(i+2);
  56. plate(length(plate) + 1) = string(i+3);
  57. i = i + 4;
  58. end
  59. else
  60. i = i + 1;
  61. end
  62. end
  63. if (i == length(string))
  64. plate(length(plate) + 1) = string(i);
  65. end
  66. output = plate;
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement