c# - Associative array from text -



c# - Associative array from text -

how parse text formated this?

data name of group: name: value name: value name: value info name of group: name: value name of group: name: value name: value

it can have multiple data , each info can have multiple named groups , within every 1 of them can multiple name value pairs number of spaces can vary within whole text means before first data there can 2 spaces , before sec none @ all.

after parsing able associative array can access info in way data[0][name of group][value name] or doing foreachs , on. possible powerfulness of regular expression?

i think can without regular expressions. scan input line line. if line contains string "data" increment data_index (initially set -1). if line looks "text:" set variable group_name text. if line looks "text_left:text_right" set variable name text_left , perform operation data[data_index][group_name][name] = text_right.

to check string grouping name, first trim check lastly character ':'. if it's not info line , not grouping name, can infer it's name/value pair.

this assumes input file well-formatted: grouping names end ':' , on. spaces in lines don't matter.

c# regex

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -