How do you loop through a string, and split the string up based on the number of characters
Way back when during our Siemens LCR days we had to limit the number of characters in OBX.5 to a length of 75. That was back when we had eGate.
Now I need to do the reversal of that and take loop through a string length and split the string up into multiple OBX or NTE based on a certain length. In reading documentation $EXTRACT can do this if you know the exact length, but in this case we don't.
So how would one loop through a string and say every 75 characters create a new OBX or NTE segment?
Thanks
Scott
as a quick approach:
/// pByLen - Length you want in each part
/// arrObx - passed by reference to store each OBx in array
ClassMethod SplitByLen(pStr As %String, pByLen As %Integer, ByRef arrObx) As %Status
{
Set (startPos,obxCntr)=0
for
{
Quit:'(startPos < $L(pStr))
Set arrObx($I(obxCntr)) = $E(pStr,$I(startPos),startPos+pByLen-1)
Set startPos = startPos + pByLen
}
Quit $$$OK
}
Scott, is there any requirement that this field be split along word boundaries such as whitespace and punctuation characters? That makes it a bit more challenging :)
The Mighty Jeffrey Drumm!
Yes there is a requirement to split on words. Otherwise we would be simply using a similar loop as above on substring and dumping the output into OBX5's.
Chuck Kozak
OK, it's quick and dirty and I'm probably doing something that will make the old-timers here laugh hysterically, but it works. The caveats are:
So anyway ...
Have fun!
utilize a for loop
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue