DarkW1nter
DarkW1nter

Reputation: 2851

Looping through values in a string variable taken from a BizTalk message

I extract a value from a BizTalk message which looks like this string:

UPX:300184-SEQNO:1-401:SHER-410:NONE-450:DEBR-480:NONE

I need to look for each occurrence of 'DEBR' which I've done, I then enter a loop for each occurrence and do the following:

Build an account number based on UPX + SEQNO (padded top 3 chars) + the number immediately before the DEBR, in this case 450, so here the account would be 300184001450.

There may be up to 4 DEBR's, and for each one I have to build a new message and make some service calls.

At the moment I call a C# utility to get the number of DEBR's so I know how many times I need to loop round building the account and doing the call.

My problem is, if there are multiples what is the best way to know which DEBR I've already processed, given that this is a string variable taken from a message?

Upvotes: 0

Views: 246

Answers (1)

Anton Gogolev
Anton Gogolev

Reputation: 115779

You can try extracting what you need with regular expressions. Start with this:

UPX\:(\d+)-SEQNO\:(\d+).+?(\d+):DEBR

For example,

var match = 
  new Regex(@"UPX\:(\d+)-SEQNO\:(\d+).+?(\d+):DEBR").
    Match("UPX:300184-SEQNO:1-401:SHER-410:NONE-450:DEBR-480:NONE");

var accountNumber = string.Format("{0}{1}{2}", 
  match.Groups[1].Value, 
  match.Groups[2].Value.PadLeft(3, '0'), 
  match.Groups[3].Value);

Upvotes: 1

Related Questions