• Post Reply Bookmark Topic Watch Topic
  • New Topic

get substring between two different delimiters and then parse it into Integer array.  RSS feed

 
Vivek Unni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Need code logic or regex to get substring between two different delimiters and then parse it into Integer array.

My Input String is : Transmitter#MSE14_REC_FTP40 #138^TPPurgeUility_test #103^YUG_Trans #57^

Output (ie. substring between "#" and "^")

138
103
57

Thanks,
Vivek
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch.

Regular expression can be used to solve this. Have a look at the Regex tutorial here.

What regex to use to get those numbers/digits between "#" and "^"? I will let you find out for your self.

Post your findings/ problems and we are willing to help
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're sure the values are between your delimiters are digits you can just use indexOf(...) and substring(...).
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek Unni wrote:Hi,

Need code logic or regex to get substring between two different delimiters and then parse it into Integer array.

My Input String is : Transmitter#MSE14_REC_FTP40 #138^TPPurgeUility_test #103^YUG_Trans #57^

Output (ie. substring between "#" and "^")

138
103
57

While an example is nice, it does not make a spec. Until you can explicitly write out the logic, you should not start coding. Your example does not make it clear why you choose 138 and not "MSE14_REC_FTP40 #138" or even "MSE14_REC_FTP40 #138^TPPurgeUility_test #103^YUG_Trans #57", as both of those strings are between a '#' and a '^'.
 
Justin Musgrove
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found guava splitter is much more flexible and easier to read than regular expression. For your use case it would look like this:



Check out more guava splitter examples

Google splitter home page
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!