echiquier1 Posted July 27, 2008 Report Share Posted July 27, 2008 Hello everyone, My request is how can I buil a macro that detect a 12 digit number in a text file? In advance thanks for the help Quote Link to comment Share on other sites More sharing options...
rberq Posted July 27, 2008 Report Share Posted July 27, 2008 Can you give a little more information? Are you trying to detect ANY number that is 12 digits, or one specific number? Can it be anywhere in the file, or is it always at the beginning of a line, etc. Quote Link to comment Share on other sites More sharing options...
echiquier1 Posted August 2, 2008 Author Report Share Posted August 2, 2008 in fact , any 12 digit number , any where in the file thanks Quote Link to comment Share on other sites More sharing options...
Cory Posted August 5, 2008 Report Share Posted August 5, 2008 Pretty simple. First copy the file to a variable EG T1. Then make a repeat storing the iteration in a var EG N1. In each iteration copy 12 characters starting at position N1 to variable T2. Convert T2 to an Integer N2 and then back to a text string T3. If T2=T3 T2 is a 12 digit integer. To control the repeat simply keep going until T2 is blank. Or in the beginning you can set an integer to the length of the string in T1 and subtract 12 and repeat that many times. This way you can use the built in repeat increment. If it's possible that there could be a 13 digit integer and you want to exclude it or if the 'number' could have left padding zeros that would count you can't use the integer converting trick. Instead repeat just as above but just copy one character at a time. If it is a number (here you can use the integer conversion trick) increment a counter If the counter reaches 12 without going over then you have found your animal. If the character is not an integer reset your counter and continue. To copy that 12 digit number simply subtract the appropriate number of spaces from the incrementor and copy 12 char from that position to another var. Quote Link to comment Share on other sites More sharing options...
echiquier1 Posted August 8, 2008 Author Report Share Posted August 8, 2008 pretty smart , especially the conversion to an integer before going back to a string type. the question now is how to know that we have reached the end of the file ? I shall have another variable for the length of the file, right? Quote Link to comment Share on other sites More sharing options...
Cory Posted August 8, 2008 Report Share Posted August 8, 2008 In my post I suggested setting an integer to the length of the string in T1-12. T1 is the string to be searched so this would be the number of repeats. Quote Link to comment Share on other sites More sharing options...
echiquier1 Posted August 9, 2008 Author Report Share Posted August 9, 2008 In my post I suggested setting an integer to the length of the string in T1-12. T1 is the string to be searched so this would be the number of repeats. Oooops, sorry for the disturb, and thanks again. Quote Link to comment Share on other sites More sharing options...
Cory Posted August 15, 2008 Report Share Posted August 15, 2008 No disturb, sorry I was terse. I was just in a hurry. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.