-2

I have variable in which sometimes big length string comes, I want to break this string based on comma(,) if string exceed the 20 characters. Suppose my string is "ABCFinancialInstitute,AMI". It should display on my html like this

ABCFinancialInstitute,
AMI

I tried this

<label *ngIf="!editMode">
        {{settingLabel.split(',')}}
      </label>

Can any one help in this. thanks in advance!!

thetechguy
  • 41
  • 7
  • 1
    Does this answer your question? [Split large string in n-size chunks in JavaScript](https://stackoverflow.com/questions/7033639/split-large-string-in-n-size-chunks-in-javascript) – old greg Dec 16 '20 at 15:40
  • @jimmysumshugar no – thetechguy Dec 16 '20 at 15:41
  • Which solutions from the linked question did you try, and how are they not working for you? Could you share your existing implementation so that others can try to reproduce any errors you are encountering? – old greg Dec 16 '20 at 15:42

2 Answers2

0

Use a regular expression to match up to 19 characters followed by either , or the end of the string ($):

settingLabel.match(/.{1,19}(?:,|$)/g)

https://regex101.com/r/1EQss6/1

If the sequences between ,s can contain more than 20 characters and you want to match them anyway as long as no , is encountered, alternate with [^,] (anything but a comma):

.{1,19}(?:,|$)|[^,]+(?:,|$)

https://regex101.com/r/1EQss6/2

CertainPerformance
  • 313,535
  • 40
  • 245
  • 254
0

It looks like you are using handlebars, jinja, or some other type of templating language (no?)

Does this work for you or can you provide more details:

{{settingLabel | replace("," "<br>") }}

Update:

Since you are using Angular 8 Would this work: https://stackoverflow.com/a/44467113/2903486

Aneuway
  • 713
  • 9
  • 20