How to reverse a string in mendix

0
How to reverse a string in mendix without using javaactions can anyone please explain in detail
asked
4 answers
3

Find the length of the string using that while loop with length > 0 and use substring(string, length-1, 1). 

answered
2

Hello, 

 

It could be possible if the String expressions had a function call ‘reverString’, which is not the case:

https://docs.mendix.com/refguide/expressions/#10-string-function-calls

 

A feasible way to do this avoiding the usage of Java is using JavaScript, called from a Nanoflow : 

 

The code for your convenience:

 

export async function reverseString(strToReverse) {
 // BEGIN USER CODE
 return new Promise((resolve, reject) => {
  return resolve(strToReverse.split("").reverse().join(""));
 } );
 // END USER CODE
}

 

answered
1

Hi yogendra jangid,
I would suggest creating a Java action and write your java code and return the Reversed String. 

Example Java link for REF: https://www.geeksforgeeks.org/reverse-a-string-in-java/

 

 

answered
0

If you wish to avoid writing java(script) code to do this, you can use the CommunityCommons function StringSplit and use '' (an empty string) as the Split Parameter.

afbeelding.png

This wil result in a list of SplitItem objects for every single character in the input string.

 

afbeelding.png

 

Simply iterate through the list and change the $Result variable

 

afbeelding.png

answered