Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #13381 > unrolled thread

parser ( based on position)

Started byabk <asha.bagesh@gmail.com>
First post2012-04-04 00:37 -0700
Last post2012-04-04 12:56 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  parser ( based on position) abk <asha.bagesh@gmail.com> - 2012-04-04 00:37 -0700
    Re: parser ( based on position) Roedy Green <see_website@mindprod.com.invalid> - 2012-04-04 12:56 -0700

#13381 — parser ( based on position)

Fromabk <asha.bagesh@gmail.com>
Date2012-04-04 00:37 -0700
Subjectparser ( based on position)
Message-ID<c94b3902-ba3c-464c-9fce-c3533641cbc9@px4g2000pbc.googlegroups.com>
Is it possible to do the following in java :
I want to parse strings and store them in a list and eventually store
it in a table.

The problem is strings have substrings which appear in different
positions and have different delimiters  . I have given examples of
strings.

I am thinking of the following
==========================

Have formats defined for Strings ( as shown below)


Can we map a string to a particular format with this delimiter and
build a "key/value" list ( which can be dumped into db. Key matches
column name)

I dont know if this is a good idea and since i am new to java, I dont
know how this can be done in java . Any ideas will be of great help.
I want a common parser to dump these values .

Thanks
===
String 1
Format1
UnitNo L1 L2 STime speed direction status preading greading freading
lreading Ireading PSource Battery1 Battery2 ID i1 i2 i3 i4 i5 i6 i7 i8
i9 i10 o1 o2 o3 o4 o5 o6 o7 o8 o9 o10 o11 o12 a1 a2 a3 a4 a5


^ID|Uid|L1|L2|Stime|Speed|Direction|Status|preading|greading|Ireading1|
Ireading2|Psource|Battery1|Battery2|I1|I2|I3|UnitNo.............
^0609|8|2829.49673|07704.82322|13.627|130.59|140312075012|2|0|A|1|0|0|
0|3.015600|12.230000|2748.26|76373.00|352024027728165|!

String 2
Format2
UnitNo L1 L2 Stime Speed Direction Status I1 I2 I3 Preading Ireading
Battery1 preading1 greading1.............
FC03 00140700 00007D04 0002E702 0001624F 00C02A9D 049C5D4C 00000014
00025A39 00000008 000FE348

Format3
String 3
^id=UnitNo&Pos=<I1><I2><Stime><Speed><Direction>.......................
^id=PTTRK30ES861001000245502&POS=<3.1><1259.429640><07735.382010><084038><260312><0.000><0.0><22><06><0><0><67><0><0><0.09><0.0><5.73><2.2><0><0.0>@


[toc] | [next] | [standalone]


#13384

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-04-04 12:56 -0700
Message-ID<0m9pn7hv8hsov07pu78uqs2ggl1hqn52q4@4ax.com>
In reply to#13381
On Wed, 4 Apr 2012 00:37:00 -0700 (PDT), abk <asha.bagesh@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>I am thinking of the following

All you might need is something like this:

Pattern delimiter = Pattern.compile( " |\||\<|\>");

Then use split.

See http://mindprod.com/jgloss/regex.html

-- 
Roedy Green Canadian Mind Products
http://mindprod.com
When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web