# String Format

**URL:** <https://forum.radzen.com/t/string-format/3395>\
**Category:** Angular\
**Created:** [April 27, 2020, 1:11pm UTC](https://forum.radzen.com/t/string-format/3395 "2020-04-27T13:11:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozgur\_agi](https://forum.radzen.com/letter_avatar_proxy/v4/letter/o/7c8e57/32.png) [@ozgur\_agi](https://forum.radzen.com/u/ozgur_agi)\
**Post date:** [April 27, 2020, 1:11pm UTC](https://forum.radzen.com/t/string-format/3395/1 "2020-04-27T13:11:13Z")

</div>

Hello,

In a datagrid, I have the following structure of string data in a column:

- word\_number\_unnecessary
- another\_one\_unncessary
- next\_unnecessary  
...

Here, I need to strip the "\_unnecessary" part of each row of this column. Can you please give me a clue how to do this? I checked the column's Format and FormatString properties but could not understand how can I use it?

Thanks,

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [April 27, 2020, 1:23pm UTC](https://forum.radzen.com/t/string-format/3395/2 "2020-04-27T13:23:59Z")

</div>

Hi @ozgur_agi,

Is the "unnecessary" part of the column data? Can you paste here how the actual data looks in JSON format? Or a screenshot of it?

---

<div class="post-metadata">

**Author:** ![ozgur\_agi](https://forum.radzen.com/letter_avatar_proxy/v4/letter/o/7c8e57/32.png) [@ozgur\_agi](https://forum.radzen.com/u/ozgur_agi)\
**Post date:** [April 27, 2020, 3:58pm UTC](https://forum.radzen.com/t/string-format/3395/3 "2020-04-27T15:58:10Z")

</div>

Hello,  
Thank you for your quick reply.  
I cannot show the actual data but a visualization is in the picture.

 ![format_string](https://forum.radzen.com/uploads/default/original/2X/f/fb3bdfb81aac2153accbc9f5358e8ad7ea018144.png)

So, basically I need to strip out the part after the last underscore.

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [April 27, 2020, 4:05pm UTC](https://forum.radzen.com/t/string-format/3395/4 "2020-04-27T16:05:59Z")

</div>

In that case you can use the replace method of the string to remove it. Try setting the Template property of the DataGrid column to something like `${data.column2.replace("_unnecessary", "")}`

---

<div class="post-metadata">

**Author:** ![ozgur\_agi](https://forum.radzen.com/letter_avatar_proxy/v4/letter/o/7c8e57/32.png) [@ozgur\_agi](https://forum.radzen.com/u/ozgur_agi)\
**Post date:** [April 28, 2020, 12:28pm UTC](https://forum.radzen.com/t/string-format/3395/5 "2020-04-28T12:28:18Z")

</div>

Thank you for this reply, it is actually working.

When I need regular expressions, how can I do that?

I tried:

- ${data.column2.replace(/^(.\*)\_([A-Z]+)$/g,"\$1")}
- ${data.column2.replace(/^(.\*)\_([A-Z]+)$/g,"$1")}

I actually need this since in other datagrids, I will have non constant string "\_unnecessary" at the end of the data, like "\_STRING", "\_INT".

Best,

---

<div class="post-metadata">

**Author:** ![ozgur\_agi](https://forum.radzen.com/letter_avatar_proxy/v4/letter/o/7c8e57/32.png) [@ozgur\_agi](https://forum.radzen.com/u/ozgur_agi)\
**Post date:** [April 29, 2020, 5:21pm UTC](https://forum.radzen.com/t/string-format/3395/6 "2020-04-29T17:21:49Z")

</div>

Hello,

can you please help with this regular expression question?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![korchev](https://forum.radzen.com/user_avatar/forum.radzen.com/korchev/32/4_2.png) [@korchev](https://forum.radzen.com/u/korchev)\
**Post date:** [April 29, 2020, 5:31pm UTC](https://forum.radzen.com/t/string-format/3395/7 "2020-04-29T17:31:33Z")

</div>

As far as I know Angular doesn't support regular expression literals in its Templates. You will need to add a method to your page.component.ts file which does the replace.

```auto
class YourPageComponent extends YourPageComponentGenerated {
     replace(value) {
        return value.replace(/^(.*)_([A-Z]+)$/g,"\$1");
     }
}

```

Then set the template like this:

`${replace(data.column2)}`

---

<div class="post-metadata">

**Author:** ![ozgur\_agi](https://forum.radzen.com/letter_avatar_proxy/v4/letter/o/7c8e57/32.png) [@ozgur\_agi](https://forum.radzen.com/u/ozgur_agi)\
**Post date:** [April 30, 2020, 8:43am UTC](https://forum.radzen.com/t/string-format/3395/8 "2020-04-30T08:43:41Z")

</div>

Solved the issue.

Thank you @korchev 🙂
