Skip to Main Content
Categories Expression Engine
Created by Ulrik Viebke
Created on Dec 5, 2024

Expression Engine: CONVERT inside a string

Please, fill in the below fields to enable the processing of your idea.

Who would benefit?

Customers with raw data, which they need to clean up using Expression Engine

What impact would it make?

No need for custom extension

How should it work?

similar to CONVERT, but converts the values from a string context. Example. A field contains the text:
12.2" x 20" x 25"
(or 12.2in x 20in x 25in)

Using a "convert string" would take the numbers and convert from the current unit of measure into a new one, but keep the characters around the individual values and it's unit intact. Technically, split by x, trim, check unit, convert value, and insert the value in the full sting again.
Another approach would be to separate values in a spring and process each part separately, and then CONCATENATE then in the end

Example expression:
=CONVERTSTRING('12.2in x 20in x 25in', 'in', 'm', 'x')

=CONVERT( SPLIT(FIELDVALUE("sourcefield"), 'x' )[0] , 'in','m')/1000
=CONCATENATE (CONVERT ( SPLIT('12.2in x 20in x 25in', ' x ')[0], 'in', 'm')/1000, 'mm x ', CONVERT ( SPLIT('12.2in x 20in x 25in', ' x ')[1], 'in', 'm')/1000, 'mm x ', CONVERT ( SPLIT('12.2in x 20in x 25in', ' x ')[2], 'in', 'm')/1000),'mm')

Result:
31mm x 51mm x 64mm

Why is it needed?

To avoid custom extensions being implemented.


Additional feedback, background or context:


  • Attach files