不使用web方法中的builtin string.length方法查找字符串长度?

时间:2016-10-18 17:37:31

标签: webmethods webmethods-caf

我想在web方法中使用pub.string.length(内置函数)找到给定字符串的长度。

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

2 个答案:

答案 0 :(得分:1)

你可以编写自己的java服务,但这听起来多余。

这是一个(尚未经过测试的)代码示例:

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();
}

答案 1 :(得分:-2)

您可以使用pub.string:substring手动计算字符串的长度,直到出现错误。 我不推荐这个 - 它不优雅,可能很慢,它仍然使用pub.string中的一个函数,你似乎在避免它。 无论如何,这是一种方法,点击链接查看图像。

webMethods代码示例 - https://i.stack.imgur.com/FE9oU.jpg

确保输入字符串不能为空 - 否则子字符串不会抛出错误,并且它将具有无限循环。