Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ output] = dasher( string )
- letters = "qwertyuiopasdfghjklzxcvbnm";
- numbers = "1234567890";
- numbercount = 0;
- lettercount = 0;
- plate = '';
- i = 1;
- while i < length(string)
- if (contains(numbers,string(i)))
- lettercount = 0;
- j = 1;
- numbercount = numbercount + 1;
- while(j+i < length(string) + 1 && contains(numbers,string(i+j)))
- j = j + 1;
- numbercount = numbercount + 1;
- end
- if (numbercount == 2)
- plate(length(plate) + 1) = string(i);
- plate(length(plate) + 1) = string(i + 1);
- plate(length(plate) + 1) = '-';
- i = i + 2;
- end
- if (numbercount == 1)
- plate(length(plate) + 1) = string(i);
- plate(length(plate) + 1) = '-';
- i = i + 1;
- end
- elseif (contains(letters,string(i)))
- numbercount = 0;
- j = 1;
- lettercount = lettercount + 1;
- while(j+i < length(string) + 1 && contains(letters,string(i+j)))
- j = j + 1;
- lettercount = lettercount + 1;
- end
- if (lettercount == 2)
- plate(length(plate) + 1) = string(i);
- plate(length(plate) + 1) = string(i + 1);
- plate(length(plate) + 1) = '-';
- i = i + 2;
- end
- if (lettercount == 3)
- plate(length(plate) + 1) = string(i);
- plate(length(plate) + 1) = string(i + 1);
- plate(length(plate) + 1) = string(i + 2);
- plate(length(plate) + 1) = '-';
- i = i + 3;
- end
- if (lettercount == 4)
- plate(length(plate) + 1) = string(i);
- plate(length(plate) + 1) = string(i+1);
- plate(length(plate) + 1) = '-';
- plate(length(plate) + 1) = string(i+2);
- plate(length(plate) + 1) = string(i+3);
- i = i + 4;
- end
- else
- i = i + 1;
- end
- end
- if (i == length(string))
- plate(length(plate) + 1) = string(i);
- end
- output = plate;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement