I am working on a project that is reading a file line by line. In these lines there may or not be a two digit hexadecimal number. For example EC, 1F, A3, 34. The line can include words, single digit numbers, a letter, or various other special characters, all are separated by spaces. This number will always be in the same spot in the line if it is present. If it is present I will need to do something special to the data on that line than say if a single digit number was present. I'm taking the line and placing it into an array as it is used for something else in the program. In regards to the design of capturing this number I am planning on using a regex expression and matches method to grab it from the original string. This will be stored in a data structure somewhere else as I will also have to add or subtract with this later on.
Would the most efficient way to capture this method be using a matcher.find() method? Or should I just grab it straight off the line since I know exactly where it will be placed? I wanted to include matches just in case the user made an error and was off by one in inputting the hexadecimal number and to check if the number is present. There is a little room to give in this input on both sides. I know I could just grab the array and use the index value of where the hexadecimal number is located but I am curious is it better program design to plan for small discrepancies like being off by a space and having that already built into your program or keep it is simple and rigid?
This is how I am currently grabbing the hexadecimal number
wordSansNumber = wordToInsert.substring(0,5);
hexaDecimalNumber = wordToInsert.substring(5,14);
justHexaDecimalFinder = hexaDecimalFinder.matcher(hexaDecimalNumber);
If the the match returns true it runs through a few operations.
Aucun commentaire:
Enregistrer un commentaire