BPM C# Split string

I’m trying to set the specified field of BPM Data to the specified expression

The field is Char3 the expression I’m trying is ttQuoteHedRow.ShipToAddrList

I can get it to display as a string but I can’t get it to split on “~”

Any clues please, I’m new to C#

@LBARKER
i think what you need is in this old post!

check out this site: https://www.dotnetperls.com/split
you can insert any character into the split command.

1 Like

Char3 = ttQuoteHedRow.ShipToAddrList.Split('~'); should do the trick, shouldn’t it?

Edit: except of course that returns an array. Silly me. OP, which element of the split up string do you need in Char3?

Wouldn’t that return an array? Don’t you need to specify the specific element?

Yes, of course. Silly me. I don’t know which element OP wants, either…

I just did this this morning on SalesRepList

this should get you the elements:

string address1 = ttQuoteHedRow.ShipToAddrList.Split('~')[0];
string address2 = ttQuoteHedRow.ShipToAddrList.Split('~')[1];
string address3 = ttQuoteHedRow.ShipToAddrList.Split('~')[2];

or you can simply put it into an array:

string addressArray[] = ttQuoteHedRow.ShipToAddrList.Split('~');
int numberOfAddressLines = addressArray.Count();
foreach (string address in addressArray){
  // do something with address variable
}
1 Like

Thanks Chris, I’m getting an error, I probably used the wrong terminology in my question

I see the problem… you dont need the first part of the statement. Instead, in the editor put the following:

ttQuoteHedRow.ShiptToAddrList.Split('~')[0]

you also dont need the semi-colon at the end.

2 Likes

@timshuwy , thats a lot closer to what I’m looking for, but it is only returning the first line of the Ship To address list

Ok so Split isn’t what you want, you probably want to replace the ~ with a line return or something:

BpmFunc.Replace(ttQuoteHedRow.ShipToAddrList, "~" , Environment.NewLine)
1 Like

@Rick_Bird, That throws this error

Double Click on the Replace function you have highlighted… it’s probably BpmFunc.Replace.

Thanks @Rick_Bird , thanks all for your input

Ricks suggestion worked

BpmFunc.Replace(ttQuoteHedRow.ShipToAddrList , “~” , Environment.NewLine )