String Reversal

Hi All,

I have a requirement where I need to reverse a string. For eg: 12345 should be changed to 54321. Does anyone of you know if we have any util that I can use?

Please let me know. Thanks for your time.

Hi Kumar,

I am currently thinking of 2 approaches:

  1. Using regular expressions if possible. (I am not sure about that)
  2. convert the string into byte arry, reverse the byte array and convert it back to a string

Most likely option 2 will result in a small java service.

Eventually some other members have further ideas on this.

Regards,
Holger

write down java service for the same. I don’t think built-in service exist for this.

Thanks,

OOTB there is no services provided in WmPubic package however you can use the Java API. There are many ways in doing this however below is one of the core code snippet:

import java.io.;
import java.util.
;

public class reverseString {
public static void main(String args) {
String input=“AliveisAwesome”;
StringBuilder input1 = new StringBuilder();
input1.append(input);
input1=input1.reverse();
for (int i=0;i<input1.length();i++)
System.out.print(input1.charAt(i));
}}>

import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataUtil;

public final class nameReverse_SVC

{

/** 
 * The primary method for the Java service
 *
 * @param pipeline
 *            The IData pipeline
 * @throws ServiceException
 */
public static final void nameReverse(IData pipeline) throws ServiceException {
	// pipeline
	IDataCursor pipelineCursor = pipeline.getCursor();
		String	string = IDataUtil.getString( pipelineCursor, &quot;String&quot; );
	pipelineCursor.destroy();
	String input = &quot;12345&quot;;
	StringBuilder input1 = new StringBuilder();
	
	
	// pipeline
	IDataCursor pipelineCursor_1 = pipeline.getCursor();
	
	IDataUtil.put( pipelineCursor_1, &quot;output&quot;,input1 );
			pipelineCursor_1.destroy();
	
			 
			input1.append(input); 
			input1=input1.reverse(); 
			
	
		
}

// --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---



// --- <<IS-END-SHARED-SOURCE-AREA>> ---

final static nameReverse_SVC _instance = new nameReverse_SVC();

static nameReverse_SVC _newInstance() { return new nameReverse_SVC(); }

static nameReverse_SVC _cast(Object o) { return (nameReverse_SVC)o; }