#How to get proper Acronym from String (french)

16 messages · Page 1 of 1 (latest)

little eagle
#

Hi,
I have this function to get acronym:

String acronym = str.replaceAll("\\B.|\\P{L}", "").toUpperCase();

But from this string : Unions de recouvrement des cotisations de sécurité sociale et d’allocations familiales
I got : UDRDCDSSEDAF

But i want this result : URSSAF

Any idea please? Is it possible?

plush deltaBOT
#

Hey, @little eagle!
Please remember to /close this post once your question has been answered!

open laurel
#
Arrays.Stream(acronym.split("\\s+"))
  .filter(s -> !Set.of("de", "des", "et").contains(s))
  .map(s -> String.of(s.charAt(0)))
  .collect(Collectors.joining())
little eagle
#

.collect(Collectors.joining()) seems not to work @open laurel

#

I have just need to see if de, des, et is suffisant

open laurel
#

ah yes, sorry

#

now

little eagle
#

Yep not to bad, but I think I'll just add an acronym column directly in my database for these fields.

open laurel
#

that's probably best

little eagle
#

That will be more precise because there I have UR(C), out the C should not leave but it is a case "impossible" to detect dynamically

open laurel
#

you don't really want to automate these

#

yeah

little eagle
#

C for cotisation

#

Thank you anyway!