Text Only
|
Text with Attachments
QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Pete on February 21, 2020, 10:33:42 am
Title:
Just parsing along some information...
Post by:
Pete
on
February 21, 2020, 10:33:42 am
Here is a nice little example of how parsing can help find changes in a file database...
Code: QB64:
[Select]
orig_concat$
=
"Pete|Steve|Bill|Norma Jean|Fell|"
new_concat$
=
"Pete|Steve|Norma Jean|Fell|"
seed
=
1
marker$
=
"|"
DO
x$
=
MID$
(
orig_concat$
,
seed
,
INSTR
(
seed
,
orig_concat$
,
marker$
)
-
seed
)
seed
=
seed
+
LEN
(
x$
)
+
LEN
(
marker$
)
PRINT
x$
,
seed
,
LEN
(
orig_concat$
)
IF
INSTR
(
new_concat$
,
x$
)
=
0
THEN
COLOR
4
,
0
:
PRINT
MID$
(
x$
,
1
,
LEN
(
x$
)
)
;
" was deleted. Good-bye "
;
MID$
(
x$
,
1
,
LEN
(
x$
)
)
;
"!"
:
COLOR
7
,
0
END
IF
LOOP
UNTIL
seed
>
LEN
(
orig_concat$
)
Pete
Title:
Re: Just parsing along some information...
Post by:
TempodiBasic
on
February 21, 2020, 05:50:11 pm
Hi Pete
very interesting concept!
But for my slow mind I prefer to have a more explicit output
like this
Code: QB64:
[Select]
orig_concat$
=
"Pete|Steve|Bill|Norma Jean|Fell|"
new_concat$
=
"Pete|Steve|Norma Jean|Fell|"
seed
=
1
marker$
=
"|"
seed2
=
1
DO
x$
=
MID$
(
orig_concat$
,
seed
,
INSTR
(
seed
,
orig_concat$
,
marker$
)
-
seed
)
seed
=
seed
+
LEN
(
x$
)
+
LEN
(
marker$
)
PRINT
x$
,
seed
,
LEN
(
orig_concat$
)
;
IF
INSTR
(
new_concat$
,
x$
)
=
0
THEN
COLOR
4
,
0
:
PRINT
MID$
(
x$
,
1
,
LEN
(
x$
)
)
;
" was deleted. Good-bye "
;
MID$
(
x$
,
1
,
LEN
(
x$
)
)
;
"!"
:
COLOR
7
,
0
ELSE
Y$
=
MID$
(
new_concat$
,
seed2
,
INSTR
(
seed2
,
new_concat$
,
marker$
)
-
seed2
)
seed2
=
seed2
+
LEN
(
Y$
)
+
LEN
(
marker$
)
' PRINT Y$, STR$(seed2), STR$(LEN(new_concat$))
PRINT
Y$
+
" "
+
STR$
(
seed2
)
+
" "
+
STR$
(
LEN
(
new_concat$
)
)
END
IF
LOOP
UNTIL
seed
>
LEN
(
orig_concat$
)
:-)
Text Only
|
Text with Attachments