B4J Question Help Regex in java


Active Member
Licensed User

i have this string in java

i want to split and add to map
then add to list
My main problem is in the Regex section.

Model                       SerialNumber          Size
GIGABYTE GP-GSM2NE3512GNTD  6479_A747_3050_150B.  512105932800
ST500DM002-1BD142           Z2AA2BG0              500105249280


Well-Known Member
Licensed User
Longtime User
you should determine whether the character(s) ending
each apparent line are cr/lf or just lf (aka nl). that
character or those characters are what you split the
string on. you'll end up with a string array with 3 items
in it.

each line appears to be tab-separated, so that's what you
would use to split each line. you'll get a string array with 3
items in it. how you turn the array into a map depends on
which of the fields is your key and how you want to handle
the remaining 2 fields. mymap.put( key, value).

"then add to list". add what? i'll assume the map (mymap):


dim mainarray() as string = regex.split( CRLF, mystring)
dim mymap
mymap initialize
for each line as string in mainarray
   dim lilarray() as string = regex.split("\t",line)
   for each item as string in lilarray
      mymap.put( lilarray(0), lilarray(1) & "|" & lilarray(2) )
dim somelist as list

if the original string uses "cr/lf" as the line separator, you'll have to
modify the first regex, otherwise you end up with a "cr" character
in each line. also, i assume the first field in each line is the map's
key. the second or third fields could be your key, but you still have
the issue of what you want to do with the other 2 fields. i concatenated
them for convenience.

once the map is populated, you add it to some list. this is how i read your
Upvote 0


Licensed User
Longtime User
Upvote 0