File parsing methods


#1

I have one file which contains 7 parameters and their respective values.This file is used for configuring hardware devices.But the problem is ,if i insert any junk values(i.e like hjhkhhdsacd) into the file,still the hardware is able to validate those parameters .So i need proper parsing of those.hence can u suggest me any example how to check those conditions??


#2

…sorry, don’t really understand what you’re asking…? If you want to know how best to parse your file, then telling us what format it uses would be kind of useful! Is it XML, JSON, etc?


#3

Example.

Let the file be a.xyz

The contents are as follows,

CommConfig = DPCP
dfdfdfdf
Mode = debug_sim
23434554
TargetSpec = LOIP

In the above file CommConfig ,Mode ,TargetSpec are parameters and DPCP,debug_sim, LOIP are resp values. and dfdfdfdf , 23434554 are junk values. So i need a logic which should throw appropriate error msg when it encounters those junk values while parsing the same.


#4

One approach would be:

Read in the whole file as a String
Chop it up into lines using StringArray::addLines
Chop each line into tokens using StringArray::addTokens
Only accept valid tokens

Or just use XML or JSON so you don’t need your own parser!


#5

Thank you Very much . . :slight_smile:


#6

The TextFieldParser object allows you to parse and process very large file that are structured as delimited-width columns of text, such as log files or legacy database information. Parsing a text file with TextFieldParser is similar to iterating over a text file, while the parse method to extract fields of text is similar to string manipulation methods used to tokenize delimited strings.


STC Technologies|Reputation Management


#7

cool…thank u.