|
Find$
Apr 26, 2018 14:50:53 GMT -5
via mobile
Post by johnnyd on Apr 26, 2018 14:50:53 GMT -5
A handy function would be to find one or more characters of one string in another string. That way you could detect hex only, numeric only, punctuation only etc.
Use: c$=find$(a$,b$) - find any characters from b$ in a$ and place the found characters in c$
Example: a$="qwertyuiop" b$="aeiou" c$=find$(a$,b$) c$ will hold "euio"
John.
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Find$
Apr 26, 2018 17:15:56 GMT -5
Post by cundo on Apr 26, 2018 17:15:56 GMT -5
I was wondering if we can achieve something like this using the RemChar function.
|
|
|
Find$
Apr 26, 2018 19:52:30 GMT -5
Post by Mark Dunham on Apr 26, 2018 19:52:30 GMT -5
A handy function would be to find one or more characters of one string in another string. That way you could detect hex only, numeric only, punctuation only etc. Use: c$=find$(a$,b$) - find any characters from b$ in a$ and place the found characters in c$ Example: a$="qwertyuiop" b$="aeiou" c$=find$(a$,b$) c$ will hold "euio" John. I would find that very useful as well especially if you have a dictionary array and are looking for specific words.
|
|
|
Find$
Apr 27, 2018 3:35:37 GMT -5
Post by johnnyd on Apr 27, 2018 3:35:37 GMT -5
....or another function findstr(a$,b$,[x]) which would look for any of the characters from b$ in a$. An option [x] would look exclusively for characters from b$ and returns:
1: found at least one character 0: no characters found
a$="1357" b$="0123456789" findstr(a$,b$) returns 1
a$="abc123" b$="0123456789" findstr(a$,b$) returns 1
a$="abc123" b$="0123456789" findstr(a$,b$,x) returns 0
a$="123" b$="0123456789" findstr(a$,b$,x) returns 1
This is ideal for verifying a hex only number: a$="01FE" b$="0123456789ABCDEFabcdef" findstr(a$,b$,x) returns 1
a$="01JK" b$="0123456789ABCDEFabcdef" findstr(a$,b$,x) returns 0
John.
|
|
|
Find$
Apr 27, 2018 5:53:55 GMT -5
Post by Rod on Apr 27, 2018 5:53:55 GMT -5
You can of course roll your own. This returns the hex number passed or an empty string.
a$="FEE1" b$="0123456789ABCDEF" print ishex$(a$,b$) a$="01JK" print ishex$(a$,b$) wait
function ishex$(a$,b$) b$=upper$(b$) a$=upper$(a$) for n= 1 to len(a$) if instr(b$,mid$(a$,n,1))=0 then illegal=1 else c$=c$+mid$(a$,n,1) end if next if not(illegal) then ishex$=c$ end function
|
|
|
Find$
Apr 27, 2018 6:35:11 GMT -5
Post by Alyce Watson on Apr 27, 2018 6:35:11 GMT -5
Rod, since this is the wishlist board and unlikely to be seen by people looking for code, why not post it on the code board as well? Very handy functions, there.
|
|