Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. Visual C#:
  2.  
  3. string testInput = null;
  4.  
  5. //The key indicates the lenght of the prefix to check, and the value contains an array
  6. //with the prefixes to check.
  7.  
  8. Hashtable prefixes = new Hashtable();
  9. prefixes.Add(6, new string[] { "LEJL. " });
  10. prefixes.Add(5, new string[] { "LEJH ", "LEJL ", "LEJ. ", "VRL. " });
  11. prefixes.Add(4, new string[] { "DØR ", "LEJ ", "DOR ", "VÆR ", "VÆR." });
  12. prefixes.Add(3, new string[] { "NR " });
  13. prefixes.Add(2, new string[] { "D ", "L ", "V " });
  14. prefixes.Add(1, new string[] { "D" });
  15.  
  16.  
  17. foreach (DictionaryEntry prefixRange in prefixes)
  18. {
  19. int lenght = (int)prefixRange.Key;
  20. if (input.Length > lenght && testInput == null)
  21. {
  22. foreach (string prefix in (string[])prefixRange.Value)
  23. {
  24. if (input.Substring(0, lenght).ToUpper().Equals(prefix) == true)
  25. {
  26.  
  27. testInput = input.Substring(lenght);
  28. }
  29. }
  30. }
  31. }
  32.  
  33.  
  34. Ruby:
  35.  
  36. testInput = nil
  37. prefixes = ["LEJL. " , "LEJH ", "LEJL ", "LEJ. ", "VRL. ","DØR ", "LEJ ", "DOR ", "VÆR ", "VÆR.", "NR ", "D ", "L ", "V ", "D" ]
  38. prefixes.each do |prefix|
  39. testInput = input.gsub(/^#{prefix}/,"") if !(input =~ /^#{prefix}/).nil?
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement