Sorting string items

0
Hi guys, Does anyone know how to sort string items?   I have an attribute (Lot No.) string that combined numbers and letters. For example : 544M1001,544M1003,544M1005,544M1002,544M1004 I want to sort it to : 544M1001,544M1002,544M1003,544M1004,544M1005   Does anyone know how to solve this problem?
asked
2 answers
0

With string manipulations. See also the documentation here: https://docs.mendix.com/refguide/string-function-calls

You first need to cut the string up by using the comma. Use the findfirst and substring to create the pieces. Store those pieces in a non persistent object. After you cut everything up (ie no comma can be found anymore) your list of non persisten objects can be used to just sort that list. Then iterate over the list to create the string again and put it back.

Regards,

Ronald

 

answered
0

Hi Muhammad Ikhwan Afiq bin Azmir,

The solution provided by  Ronald has mentioned is absolutely correct, but it will be easy to use Split String java action from the community commons module. In your microflow, you can use StringSplit java action with key as  ‘ , ’ in your case, the above java action will return a list object from the string with, separated, after the java action you use List operation Activity and use Sort option. Then Iterate over the list and recreate your string in the format you want. 

Thanks,

Dinesh

answered