Help create java service pubstringindexOf

I am using B2B server v3.6. I need the service pub.string.indexOf, which I fuess is not available with 3.6, but a later version. I tried to manipulate the other string services, but was unusccessful. This seems like a pretty simple service. Is there a way I can get the code for this one service, without upgrading to a higher version?

I am trying to take a string, search for a set group of characters, and return the group of characters if it found.

in string: 12345abc4321
search for ‘abc’ if found, return ‘abc’, if not, return null (or -1). Tha

Hi Brian,
You can write your own Java Service to do that. After all webMethods gives a Java service for that.


I DO have the indexOf service, but that doesn’t extract the portion of the string.

Any thoughts?

I am confused.
indexOf will only give you the index of the occurance of search string. That service will not extract it. You should use substring service to extract it by passing the results of indexOf to subString service.
Hope I am understanding your issue.

Yeah, that is the correct assumption. For some reason, I thought I didn’t have the indexOf service. After I realized I did have it, I used the indexOf service to get the start of the string, then used substring service to get the value. So that part is good.

Another question. I want to extract something like #$$$$#$, where # = a number value, and $ = a letter value (so I am just looking for the number/letter pattern, not specific values). Do you know how I would go about doing this? I know there are similar values for manipulating time using characters, but I am not aware of anything for letter/number values.

Any thought?


You want to use Regular Expressions. There is an appendix at the back of the WM developer manual that covers this. Plus, any good java book will provide you with the answer. It allows for pattern matching.


Need more real life examples…for your second question.

I totally agree with Ray. Way to go is regular expressions for search string.

Thanks, I think I can probably work something out with those regular expressions. I am just having a hard time using them. I tried to do the sample {doc.p[/web.ethods/].text} but can’t get that to work.

I am using the indexOf service. The in string would be a field where someone would type in a part number, but might also type in some additional text. The field can also be blank. I then made the substring {doc.p[/web.ethods/].text}.

So the idea here is that I would input the string containing the part number values, check for the first occurance of the substring within that string (if it does occur), add 5 charcaters to the beginning index (for the length of the part number), then extract the part number and map it to the appropriate field.

I am getting a -1 (not finding the string) for this. Any thoughts?

I am getting nothing…
/\d\w\d\d\d/ and

That should be the correct expressions for number only (\d) and alphanumeric (\w). I am not getting any value returned???

I think we’re all mixing things a little bit here. Let’s see if I understand what we’re trying to solve.

First, there was this question:

Given a string 12345abc4321, extract abc

This can be done using pub.string:indexOf, a branch step and pub.string:substring. Neither of these services support regular expressions, so don’t try to pass a regular expression. You can only search for one substring at a time at it must be an exact match to get a hit.

Second, there was a follow-up:

Given a string of the form #$$$$#$, where # = a number value, and $ = a letter value, extract the $$$$ portion.

Regular expressions within FLOW will work if you’re only interested in matching the pattern. You specify a branch step, and then for the labels you specify the regular expression you want to match for the leg of the branch to be taken. For example:

branch on /aString
– /.+/: MAP (aString has one or more characters)
– /^SE/: MAP (aString starts with SE)
– /^.{2,3}$/: MAP (aString is any 2 or 3 char string)
– 1: MAP (aString is 1)
– $default: MAP (aString doesn’t match any of the above)

Note that to use a regular expression in a label, you surround the expression with slashes. Do not use the curly braces or the doc.p prefix you show in your example–that syntax is for use within HTML (dsp) pages.

My guess is that using regular expressions within FLOW step labels will not do what you need–they only indicate a pattern match, they don’t extract any parts of the input string.

The quickest way to get what you need is probably to write a Java service that does what you need. Loop over the characters in the string until you hit the first letter, record the index, continue til you hit a number or end of string and record the end index. Then use String.substring() to get the substring and return it in the pipeline.

Hope this helps.

Hi gurus,

I am trying to find out a regular exp syntax to search for a particular word in the string…

Any ideas for the syntax please??


To find if “foo” exists within a string, do this:

BRANCH on myVar
/foo/: MAP
$default: MAP (no foo in myVar)

If myVar contains, “foobar”, “sofoobar” or “barfoo”, the /foo/ branch will be executed.

Thanks Rob…I have put the exact same syntax and it worked…


some how my mind is not with me today