|
Post by milfredo on Jan 10, 2021 23:02:13 GMT -5
Have a project I am working on and I need some help with some logic and use of Mid$
The problem is pulling out the number that represents dollar amount usually in the thousands in the following examples....
ALW10000n1x ALW5000n1x,
G1100000 (first two is G1 and then following is number I need
Mdn25000strhcp
There are others but you get the idea. Thanks
Milfredo
|
|
|
Post by honkytonk on Jan 11, 2021 1:11:21 GMT -5
Experts will certainly make it shorter
a$="Mdn25000strhcp" b$="": flag=0: n$="1 2 3 4 5 6 7 8 9 0" for x=1 to len(a$) for t=1 to 10 if mid$(a$,x,1)=word$(n$,t) then dx=x: flag=1: exit for next t if flag=1 then exit for next x b$="" for x=dx to len(a$) b$=b$+mid$(a$,x,1) next x print b$ carac$="a b c d e f g h i j k l m n o p q r s t u v w x y z" c$="": flag=0 for x=1 to len(b$) for t=1 to 26 if mid$(b$,x,1)=word$(carac$,t) then fx=x: flag=1: exit for next t if flag=1 then exit for next x c$="" for x=1 to fx-1 c$=c$+mid$(b$,x,1) next x print c$
|
|
|
Post by Rod on Jan 11, 2021 3:07:58 GMT -5
How is the string created? Can you not introduce , separation? Going to be hard getting G1 parsed. Is the first alpha always supposed to be three? Did you strip the space off the end of G1?
|
|
|
Post by milfredo on Jan 11, 2021 17:20:29 GMT -5
Rod. These are just as they present from the data file. That is why I am having so much problem. Some numbers are 5 characters long. Some six and some even 7 long. ie; 5000 50000 100000 And they are attached to the letter designation of the race. The last part is the race restrictions. Nix means non-winner 1 race in so many months. Or it could be N2x and so forth.
|
|
|
Post by milfredo on Jan 11, 2021 17:22:50 GMT -5
Thanks Honky. i will certainly give it a try.
|
|
|
Post by Rod on Jan 12, 2021 3:03:58 GMT -5
You say letter designation of the race but you give an example G1 is the letter designation of that race G or G1? All you need to do is discard the alpha characters at the front then val() the remainder. Liberty will automatically ignore non numeric trailing characters. So can you get the race designation from elsewhere. Knowing that we are looking for G1 will help.
|
|
|
Post by honkytonk on Jan 12, 2021 6:55:44 GMT -5
Thanks Honky. i will certainly give it a try. To have the result in numerical it is necessary to add: c=val(c$) print c
|
|
|
Post by Rod on Jan 12, 2021 9:29:29 GMT -5
I think the real problem is that the race name is not a consistent length, if it was it would be easy. So do we know all the race venue names? Can we hold them in a list?
d$(1)="ALW10000n1x" d$(2)="ALW5000n1x" d$(3)="G1100000" d$(4)="Mdn25000strhcp" for n=1 to 4 print val(right$(d$(n),len(d$(n))-3)) next
|
|
|
Post by Carl Gundel on Jan 12, 2021 11:26:55 GMT -5
Presumable there will never be any numeric characters in the race name?
|
|
|
Post by honkytonk on Jan 12, 2021 12:45:33 GMT -5
@ Rod;
Good for: "ALW10000n1x" Bad for: "Mdn25000strhcp" The code at: yesterday at 7:11 am is generalist. We have to see to compact it.
|
|
|
Post by tsh73 on Jan 12, 2021 14:11:08 GMT -5
More then one way?
Results:
Got: ALW10000n1x Out: 10000 as number=10000 Got: ALW5000n1x Out: 5000 as number=5000 Got: G1100000 Out: 100000 as number=100000 Got: Mdn25000strhcp Out: 25000 as number=25000 Got: 123number head Out: 123 as number=123 Got: 123456 Out: 123456 as number=123456 Got: 123e56 Out: 123 as number=123 Got: sorry, No numbers Out: Error: No numbers as number=0.0
while 1 read a$ if a$ = "XIZZY" then exit while print "Got: ";a$ 'special case if left$(a$,2)="G1" then a$=mid$(a$,3) 'strip first two chars 'skip any non-numbers lastP=len(a$) p = 1 while instr("0123456789", mid$(a$,p,1))=0 p=p+1 if p>lastP then exit while wend 'print , p, mid$(a$,p), val(mid$(a$,p)) if p>lastP then res$="Error: No numbers" else 'skip till numbers end q=p while instr("0123456789", mid$(a$,q,1)) q=q+1 if q>lastP then exit while wend q=q-1 'print , q, mid$(a$,p, q-p+1) res$=mid$(a$,p, q-p+1) end if print "Out: ";res$, "as number=";val(res$) wend end
data "ALW10000n1x" data "ALW5000n1x" data "G1100000" '(first two is G1 and then following is number I need data "Mdn25000strhcp" data "123number head" data "123456" data "123e56" data "sorry, No numbers" data "XIZZY"
|
|
|
Post by Rod on Jan 12, 2021 15:20:44 GMT -5
My code runs OK, Anatoly shows us how to use a known name "G1" I say again the problem is not separating alpha numeric characters the problem is the race name "G1", which contains numeric data.
|
|
|
Post by Carl Gundel on Jan 12, 2021 19:53:01 GMT -5
My code runs OK, Anatoly shows us how to use a known name "G1" I say again the problem is not separating alpha numeric characters the problem is the race name "G1", which contains numeric data. Are race names always at least 2 characters?
|
|
|
Post by Rod on Jan 13, 2021 2:48:40 GMT -5
Milfredo needs to clarify, in his first post the race names seem to be mostly three characters long.
|
|
|
Post by Carl Gundel on Jan 13, 2021 8:34:50 GMT -5
Milfredo needs to clarify, in his first post the race names seem to be mostly three characters long. Is there another source where you read the names of the races so you know what you're about to read?
|
|