Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
gino2780
Creator
Creator

Format num into string (num+special character)

Hello,

 

i have a quick question with regard to formating a field that contains numbers and or numbers+special characters into one format of my choice through script/data editor:

 

Status Quo (problem):

row_num field1
1 0000000000
2 00-000-0000/0
... ...

 

Target (solution):

row_num field1_new
1 00-000-0000/0
2 00-000-0000/0
... ...

 

How can i achive this?

Thank you in advance.

Labels (2)
1 Solution

Accepted Solutions
theoat
Partner - Creator III
Partner - Creator III

Hey,

You can try this :
=left(keepchar(champ1,'0123456789'),2) & '-' & mid(keepchar(champ1,'0123456789'),3,3) & '-' & mid(keepchar(champ1,'0123456789'),6,4) & '/' & right(keepchar(champ1,'0123456789'),1)


Kind regards,
Théo ATRAGIE.

View solution in original post

3 Replies
henrikalmen
Specialist
Specialist

Assuming the values in field1 are strings that always consist of ten digits (or null/empty) you could do this:

left(Field1,2)&'-'&mid(Field1,3,3)&'-'&mid(Field1,6,4)&'-'&right(Field1,1)

The resulting field will be a text field with your desired format.

EDIT: Yes of course, use keepchar(Field1,'0123456789') as suggested by @theoat - I should have seen that.

theoat
Partner - Creator III
Partner - Creator III

Hey,

You can try this :
=left(keepchar(champ1,'0123456789'),2) & '-' & mid(keepchar(champ1,'0123456789'),3,3) & '-' & mid(keepchar(champ1,'0123456789'),6,4) & '/' & right(keepchar(champ1,'0123456789'),1)


Kind regards,
Théo ATRAGIE.

gino2780
Creator
Creator
Author

That worked out pretty well. Thank you!