Find string length without using builtin string.length method in web methods?

981 views Asked by At

I want to find length of given string with out using pub.string.length (built in function) in web methods .

 Ex:If we give name "abcdef" i want result like 6 .
2

There are 2 answers

0
GrahamA On

You could write your own java service, but that sounds redundant to me.

Here's an (as yet untested) code sample:

public static final void checkStringSize(IData pipeline)
        throws ServiceException {

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String  inputString = IDataUtil.getString( pipelineCursor, "inputString" );
    pipelineCursor.destroy();

    long length = -1;
    length = inputString.length();

    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    IDataUtil.put( pipelineCursor_1, "length", ""+length );
    pipelineCursor_1.destroy();
}
0
GrahamA On

You could manually count the length of the string by using pub.string:substring until it gets an error. I wouldn't recommend this - it's inelegant, possibly quite slow and it still uses a function from pub.string, which you appear to be avoiding. Anyway, here's a way to do it, click the link to see the image.

webMethods code sample - https://i.stack.imgur.com/FE9oU.jpg

Just make sure the input string cannot be null - otherwise the substring won't throw an error and it will have an infinite loop.