Author Topic: Just parsing along some information...  (Read 2747 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Just parsing along some information...
« 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]
  1. orig_concat$ = "Pete|Steve|Bill|Norma Jean|Fell|"
  2. new_concat$ = "Pete|Steve|Norma Jean|Fell|"
  3. seed = 1
  4. marker$ = "|"
  5.     x$ = MID$(orig_concat$, seed, INSTR(seed, orig_concat$, marker$) - seed)
  6.     seed = seed + LEN(x$) + LEN(marker$)
  7.     PRINT x$, seed, LEN(orig_concat$)
  8.     IF INSTR(new_concat$, x$) = 0 THEN
  9.         COLOR 4, 0: PRINT MID$(x$, 1, LEN(x$)); " was deleted. Good-bye "; MID$(x$, 1, LEN(x$)); "!": COLOR 7, 0
  10.     END IF
  11. LOOP UNTIL seed > LEN(orig_concat$)
  12.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Just parsing along some information...
« Reply #1 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]
  1. orig_concat$ = "Pete|Steve|Bill|Norma Jean|Fell|"
  2. new_concat$ = "Pete|Steve|Norma Jean|Fell|"
  3. seed = 1
  4. marker$ = "|"
  5. seed2 = 1
  6.     x$ = MID$(orig_concat$, seed, INSTR(seed, orig_concat$, marker$) - seed)
  7.     seed = seed + LEN(x$) + LEN(marker$)
  8.     PRINT x$, seed, LEN(orig_concat$);
  9.  
  10.     IF INSTR(new_concat$, x$) = 0 THEN
  11.         COLOR 4, 0: PRINT MID$(x$, 1, LEN(x$)); " was deleted. Good-bye "; MID$(x$, 1, LEN(x$)); "!": COLOR 7, 0
  12.     ELSE
  13.         Y$ = MID$(new_concat$, seed2, INSTR(seed2, new_concat$, marker$) - seed2)
  14.         seed2 = seed2 + LEN(Y$) + LEN(marker$)
  15.         ' PRINT Y$, STR$(seed2), STR$(LEN(new_concat$))
  16.         PRINT Y$ + "   " + STR$(seed2) + "   " + STR$(LEN(new_concat$))
  17.     END IF
  18. LOOP UNTIL seed > LEN(orig_concat$)
  19.  
:-)

Programming isn't difficult, only it's  consuming time and coffee