i have string looks this
"21 4\n21 2 _ _ 19 11\n 12 _ _ 1 _ _\n_ _ _ 7 13 _"
(there blank space between 21 , 4, 21 , 2, 2 , _, etc)
i loop through it, extract each number, character _ or \n.
(basically split string on blank spaces , on \n)
using substring not work because elements have more 1 character (like 21 or 13)
if easiest way convert string list like
["21" "4" "\n" "21" "2" "_" "_" "19" "11" "\n"...]
that fine not sure how it.
here started. not use regular expressions - repeated use of read
.
#lang racket (define (parse-line line) (define in (open-input-string line)) (for/list ([sym (in-port read in)]) (~a sym))) (define (parse str) (define in (open-input-string str)) (for/list ([line (in-lines in)]) (parse-line line))) (parse "21 4\n21 2 _ _ 19 11\n 12 _ _ 1 _ _\n_ _ _ 7 13 _")
the output is:
'(("21" "4") ("21" "2" "_" "_" "19" "11") ("12" "_" "_" "1" "_" "_") ("_" "_" "_" "7" "13" "_"))
Comments
Post a Comment