0

I have a string contains multi language text as follow

{|en|}Audio Albums{|/en|}{|ar|}الألبومات الصوتية{|/ar|}

I need a function to get the text of specific language

getText("en") should returns Audio Albums

I think I have to use regular expression.

Tom
  • 16,842
  • 17
  • 45
  • 54
Mohamad Shaker
  • 1,466
  • 2
  • 14
  • 21
  • This sounds more like you want a better String format and use a corresponding parser. For example csv (or dsv) or JSON etc. – Tom Oct 28 '15 at 18:58
  • Possible duplicate of [How to split a string in Java](http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – Bob Oct 28 '15 at 19:01
  • Unfortunately, I must working with this format because it comes form API – Mohamad Shaker Oct 28 '15 at 19:02

1 Answers1

1

This should work:

Pattern pattern = Pattern.compile("\{\|"+lang+"\\|\\}(.*)\\{\\|/"+lang+"\|\}");
Matcher matcher = pattern.matcher(content);
return matcher.find() ? matcher.group(1) : null;
Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43