delete a filed from repeating fields
I am trying to delete a field based on a value in one of the subfields. I would like to remove the below Field with the Field value "Field8". I know how to find the number of fields and iterate. If I just use "" I still get a tilde at the end.
Ex .
|Field^Field1^Field3~Field4^Field5^Field6~Field7^Field8^Field8
Comments
If you want to remove the N-th field, in the your example, "Field8" is the 6-th field, then:
set fields = "Field^Field1^Field3~Field4^Field5^Field6~Field7^Field8^Field8"
set N=6
set $piece(fields, "^", N, N+1) = $piece(fields, "^", N+1)If you have to work with subfields, you have to get first those subfields in a temporary variable, for example, in the above example, you want to remove "Field3" then do this:
set temp=$piece(fields, "^", 3) // get the subfields
set N=1
set $piece(temp, "~", N,N+1) = $piece(temp, "~", N+1)
set $piece(fields, "^", 3) = temp // put the subfields back into the outer stringIf you want to remove the N-th field, in the your example, "Field8" is the 6-th field, then:
set fields = "Field^Field1^Field3~Field4^Field5^Field6~Field7^Field8^Field8"
set N=6
set $piece(fields, "^", N, N+1) = $piece(fields, "^", N+1)If you have to work with subfields, you have to get first those subfields in a temporary variable, for example, in the above example, you want to remove "Field3" then do this:
set temp=$piece(fields, "^", 3) // get the subfields
set N=1
set $piece(temp, "~", N,N+1) = $piece(temp, "~", N+1)
set $piece(fields, "^", 3) = temp // put the subfields back into the outer stringsorry, a doubleclick by mistake...
May be the underlying software could prevent such stupid things in the future...