String Function

-2
How to reverse a string in mendix
asked
2 answers
1

Probably easiest is creating a Java-action doing that for you, for instance using the Apache commons library

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.12.0</version>
</dependency>

public String reverseUsingApacheCommons(String MyInput) {
    return StringUtils.reverse(MyInput);
}

or if you want to stay independent:

public java.lang.String executeAction() throws Exception
{
	// BEGIN USER CODE
	
	char[] in = Parameter.toCharArray();
	int begin=0;
	int end=in.length-1;
	char temp;
	while(end>begin){
		temp = in[begin];
		in[begin]=in[end];
		in[end] = temp;
		end--;
		begin++;
	}
	return new String(in);
    // END USER CODE
}

but if you want to do this in Mendix:

  • create variable ‘ReversedString’
  • make a loop, with number of loops = the length of string
    • each time take of the first character using substring($oldstring,0,1)
    • prepend that letter to ‘ReversedString’
answered
1
answered