1

I am working on a android project doing things related parsing.suppose I want to split the string into custom format

My String

Power supply will be suspended in the following areas on 13-04-15 between 9.00 A.M. to 2.00 P.M. for maintenance work. NUNGAMBAKKAM AREA : Nungambakkam High road(Door no. 33 to 66), Ponnankipuram, Avenue road, New street. TI CYCLE AREA : Cholapuram Main road, Complete Thiruvenkata nagar, Stedford Hospital, Lenin nagar, Teachers colony, Sivananda nagar, Municipal Court and CTH road, Post office, Railway station road, School area, Ramapuram, South park st, Ambattur market, Thasildhar office

So I want to split the string into like this

Power supply will be suspended in the following areas on 13-04-15 between 9.00 A.M. to 2.00 P.M. for maintenance work
NUNGAMBAKKAM AREA
Nungambakkam High road(Door no. 33 to 66)
Ponnankipuram
Avenue road
...........
Thasildhar office

So how can I get this android.help me to get the values

6
  • make use of delimiter instead of space Commented Apr 14, 2015 at 5:06
  • What type of delimiter ? I have no idea Commented Apr 14, 2015 at 5:08
  • like ; or $ or % or & Commented Apr 14, 2015 at 5:09
  • In your input string put a special character that means "new line here" Commented Apr 14, 2015 at 5:09
  • @LachlanGoodhew-Cook What like \n ? Commented Apr 14, 2015 at 5:10

3 Answers 3

3
(?<=[a-z])\.(?=\s*[A-Z])|[,:]

You can try this.See demo.

https://regex101.com/r/sJ9gM7/88

For java it would be

(?<=[a-z])\\.(?=\\s*[A-Z])|[,:]
Sign up to request clarification or add additional context in comments.

2 Comments

i got error when using this String[] result=subString.split(('?<=[a-z])\.(?=\s*[A-Z])|[,:]');
@JosSat use (?<=[a-z])\\.(?=\\s*[A-Z])|[,:]
0

What you are trying to do is very hard, unless it involves a lot of hardcoding or reconsidering how you store a string. Computers don't work like human brains, so you can only tell them at which character you want it to split or at which index of character. I'd advise you to use some String which will signal intent to breaking line, like <LF> (line feed), then you can use String built-in method:

String array[] = string.split("<LF>");

Comments

0

You can split from ","(it is easy to implement. there are so many tutorials available online).

Please try to implement by yourself first and if you face problem in implementation then only post question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.