String Manipulation
|
10-15-2023, 12:43 PM
(This post was last modified: 10-15-2023 05:41 PM by Giuseppe Donnini.)
Post: #3
|
|||
|
|||
RE: String Manipulation
If lists are permitted by the logic of your program, it would certainly be easier.
If, on the other hand, you must use strings, here is a way (in User RPL) to convert them to appropriately formatted lists: \<< DEPTH @ Record current stack depth. 1 - @ Take input string into account. \-> s @ Save stack depth as lambda variable s. \<< WHILE @ Start conditional loop. DUP "|" POS DUP @ Keep going as long as we find "|" characters. REPEAT DUP2 @ Cut out next substring: 1 - @ - Compute position of last character. 1 @ - Position of first character is always equal to one. SWAP SUB @ - Cut. ROT ROT @ Crop remaining string: 1 + @ - Compute position of first character. MAXR @ - Position of last character is always equal to +oo. \->NUM @ - Safeguard in case constants are symbolic (default). SUB @ - Crop. END DROP @ Drop left-over result of POS (zero, by now). DEPTH s - @ Compute number of list elements. \>> \->LIST @ Build final list. \>> Your example: ( "ABC|BC|JKLMN|WXYZ" --> { "ABC" "BC" "JKLMN" "WXYZ" } ) Some special case examples: ( "|AB|CD" --> { "" "AB" "CD" } ) ( "AB|CD|" --> { "AB" "CD" "" } ) ( "AB||CD" --> { "AB" "" "CD" } ) ( "|AB||CD|" --> { "" "AB" "" "CD" "" } ) |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
String Manipulation - rickster - 10-15-2023, 01:11 AM
RE: String Manipulation - John Keith - 10-15-2023, 12:33 PM
RE: String Manipulation - Giuseppe Donnini - 10-15-2023 12:43 PM
|
User(s) browsing this thread: 1 Guest(s)