Post Reply 
Emu48 Edit a CSV File
01-05-2022, 12:14 PM
Post: #13
RE: Emu48 Edit a CSV File
(01-04-2022 11:32 PM)MNH Wrote:  I'm curious about the backslashes...
...
I don't understand your use of OVER. Wouldn't there be only one object on the stack? Also, you declare 3 local variables, but there would only be 2 objects on the stack.

The backslash syntax for escaping special characters works on the 50g, but not on the 48gx. A different entry method can be used on the 48gx (using C$ n). See below for what this looks like.

I believe I caused more confusion than help when I posted the REPLS program. That program was meant to be used as a subroutine that would provide a similar function to SREPL, not as a complete program on its own to give the result you were seeking.

The following is a more complete example of what I meant to suggest. It uses the same basic structure and naming of objects that you originally posted. To get the desired outcome, press the menu key for the STORE program. It assumes that the string to be converted is already stored into an object named "FILE", and that the results are to be stored into an object named "PNTS". REPLS is a subroutine which is called by "STORE", and needs to be present in the same directory (or any parent directory in the 48gx hierarchy).

The C$ (counted string) syntax allows you to specify the count of following characters that are considered to be a single string. It allows a more succint way to enter a double quote (") character than using something like "{" 34 CHR +.

I hope this clarifies things for you. Please keep in mind that this is simply meant as an alternative -- I'm not trying to suggest that this is ultimately the best way to do this. This does, however, give you a function (REPLS) that can be used by other programs for targeted substring replacement applications.

Code:
DIR

FILE
"248,1529945.480,521921.773
249,1530002.951,521922.245
251,1530058.926,521921.687
252,1530114.903,521923.001
254,1530221.977,521924.059"

PNTS
{ }

STORE
\<<
   FILE              @ recall source string to stack
   C$ 2 {" SWAP +    @ place {" chars at beginning
   C$ 2 "} +         @ place "} chars at end
   10 CHR            @ place linefeed char on stack
   C$ 3 " "          @ place " " chars on stack
   REPLS             @ replace all linefeeds with " "
   STR\->            @ convert the resulting string to an RPL object
   'PNTS' STO        @ store the result in PNTS
\>>

REPLS
\<<
   OVER SIZE                     @ get length of target string
   \-> targ new len              @ assign locals
   \<<
      ""                         @ initial result: empty string
      WHILE
         OVER targ POS DUP       @ loop while target found in remaining source
      REPEAT
         ROT DUP2                @ duplicate target pos/remaining source
         1 ROT OVER - SUB        @ extract chars preceding target
         new + SWAP ROT          @ append repl chars and reposition
         len + 1E8 SUB           @ extract remaining chars
         ROT ROT +               @ reposition/append to result
      END
   \>>
   DROP                          @ drop leftover POS result (0)
   SWAP +                        @ append remaining source to result
\>>

END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Emu48 Edit a CSV File - MNH - 12-30-2021, 07:24 AM
RE: Emu48 Edit a CSV File - MNH - 12-30-2021, 04:34 PM
RE: Emu48 Edit a CSV File - MNH - 12-30-2021, 10:30 PM
RE: Emu48 Edit a CSV File - DavidM - 12-31-2021, 10:54 AM
RE: Emu48 Edit a CSV File - MNH - 12-31-2021, 06:11 PM
RE: Emu48 Edit a CSV File - MNH - 01-01-2022, 04:41 AM
RE: Emu48 Edit a CSV File - DavidM - 01-04-2022, 03:48 PM
RE: Emu48 Edit a CSV File - MNH - 01-04-2022, 11:32 PM
RE: Emu48 Edit a CSV File - DavidM - 01-05-2022 12:14 PM
RE: Emu48 Edit a CSV File - DavidM - 01-08-2022, 11:22 AM
RE: Emu48 Edit a CSV File - MNH - 01-08-2022, 04:41 PM
RE: Emu48 Edit a CSV File - MNH - 01-08-2022, 07:41 PM
RE: Emu48 Edit a CSV File - DavidM - 01-09-2022, 02:34 PM
RE: Emu48 Edit a CSV File - DavidM - 01-10-2022, 10:50 AM
RE: Emu48 Edit a CSV File - MNH - 01-09-2022, 08:39 PM
RE: Emu48 Edit a CSV File - rprosperi - 01-10-2022, 04:01 AM
RE: Emu48 Edit a CSV File - DavidM - 01-10-2022, 12:41 PM
RE: Emu48 Edit a CSV File - DavidM - 01-14-2022, 04:25 PM
RE: Emu48 Edit a CSV File - MNH - 01-15-2022, 07:34 PM
RE: Emu48 Edit a CSV File - MNH - 01-04-2022, 11:06 PM
RE: Emu48 Edit a CSV File - John Keith - 12-31-2021, 06:51 PM
RE: Emu48 Edit a CSV File - MNH - 12-31-2021, 07:58 PM
RE: Emu48 Edit a CSV File - MNH - 01-04-2022, 11:39 PM
RE: Emu48 Edit a CSV File - Eric Rechlin - 01-05-2022, 03:22 PM
RE: Emu48 Edit a CSV File - MNH - 09-04-2022, 09:56 PM



User(s) browsing this thread: 3 Guest(s)