Tasp
Full Member
Posts: 215
|
Post by Tasp on Nov 8, 2020 11:56:52 GMT -5
Trying to remove all non numeric chars from a string, is there an opposite to REMCHAR$? It's easier to specify the chars I want rather than to attempt to guess what random chars a user is likely to enter, including non ASCII ones.
NUMBER$ = "1a2b3c"
CheckString$ = "0123456789" NumericOnly$ = remchar$(NUMBER$, CheckString$)
PRINT NumericOnly$
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Nov 8, 2020 13:06:33 GMT -5
I've created this little routine to do the job, but thought they'd be a built in one for this?
NUMBER$ = "1a2b3c=-34332=4-32=4-2*-/dfn7y345ybw4rt7w89r34b34r2xzvcs345ÐOÐN9"
CheckString$ = "0123456789"
FOR a = 0 TO LEN(NUMBER$) digit$ = MID$(NUMBER$, a, 1) print digit$ IF INSTR(CheckString$, digit$) > 0 THEN NumericOnly$ = NumericOnly$ + digit$ END IF NEXT
NUMBER$ = NumericOnly$
print NUMBER$
|
|
|
Post by Carl Gundel on Nov 8, 2020 15:24:21 GMT -5
I've created this little routine to do the job, but thought they'd be a built in one for this?
NUMBER$ = "1a2b3c=-34332=4-32=4-2*-/dfn7y345ybw4rt7w89r34b34r2xzvcs345ÐOÐN9"
CheckString$ = "0123456789"
FOR a = 0 TO LEN(NUMBER$) digit$ = MID$(NUMBER$, a, 1) print digit$ IF INSTR(CheckString$, digit$) > 0 THEN NumericOnly$ = NumericOnly$ + digit$ END IF NEXT
NUMBER$ = NumericOnly$
print NUMBER$
Maybe your suggestion might make a good addition, but doing what you need is actually really easy by just using the REMCHAR$() twice, like so: NUMBER$ = "1a2b3c=-34332=4-32=4-2*-/dfn7y345ybw4rt7w89r34b34r2xzvcs345ÐOÐN9"
CheckString$ = "0123456789" filter$ = remchar$(NUMBER$, CheckString$) c$ = remchar$(NUMBER$, filter$) print c$
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Nov 12, 2020 10:48:52 GMT -5
Never thought of using it like that. Thanks! Do I get royalties!?!!
|
|
|
Post by Carl Gundel on Nov 12, 2020 15:32:44 GMT -5
Never thought of using it like that. Thanks! Do I get royalties!?!! We both do!
|
|