3 Replies - 622 Views - Last Post: 23 March 2017 - 03:04 AM Rate Topic: -----

#1 tontondp21   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-March 17

How to minimize a string result in java

Posted 22 March 2017 - 12:32 PM

I want to minimize this string "AHHHAAAAARTFUHLAAAAAHV" to "AHHHAARTFUHLAHV". Removing excessive "A's" would be my only option. I tried using a split function (with a delimiter of "AAAA[^A]") to make it look like this [AHHHA, AAAA, RTFUHLAA, AAAA, HV]. But now im at lost how to manipulate those indices with "AAAA"s now to arrive to my desired output.

String y = "AHHHAAAAARTFUHLAAAAAAHV";
  String x = "AHHHAARTFUHLAHV"; //desired match or output

  String [] test = y.split("(?=AAAA[^A]|(?<=AAAA(?=[^A])))");




Is This A Good Question/Topic? 0
  • +

Replies To: How to minimize a string result in java

#2 tontondp21   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-March 17

Re: How to minimize a string result in java

Posted 22 March 2017 - 01:47 PM

I have this string "AHHHAAAAAARTFUHLAAAAAHV" and i want to minimized it to "AHHHAARTFUHLAHV". Notice that the first occurrence of successive A's is 6 and the next is 5. So I can't use:

 System.out.println("AHHHAAAAAARTFUHLAAAAAHV".replaceAll("A{4}(?!A)", "")); 


because of the irregular size of A's is there anyway around to make it "AHHHAARTFUHLAHV"?
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15968
  • View blog
  • Posts: 63,908
  • Joined: 12-June 08

Re: How to minimize a string result in java

Posted 22 March 2017 - 01:48 PM

Please do not create duplicate topics. Merging.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3729
  • View blog
  • Posts: 17,048
  • Joined: 20-September 08

Re: How to minimize a string result in java

Posted 23 March 2017 - 03:03 AM

Quote

I want to minimize this string

Do we take it that you mean 'this string' and strings like it using the same principles?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1