String Processing (Finding a character, trimming a string)

doom1701

Member
I'm just going to be honest--I'm wiped from a big upgrade this weekend and I'm hoping someone will do a little part of my job for me.

The upgrade took a value in a field and appended a huge string to the end of it. And apparently our assistant controller uses that field, so his report is now broken. I want to fix the value, removing the "|Upgraded from v5.5 to v6" tag that it placed at the end of it. I want to find the pipe character and include only the text before it. As an example, here's about what is in one of the fields:

pv-ice|Upgraded from v5.5 to v6

The piece to the left of the pipe varies in size; the piece to the right *seems* consistent but I'd rather count on the delimiter, not the length. I want to do this to the entire table:

for each table:
if table.myfield (contains a pipe) then do:
assign table.myfield = (everything to the left of the pipe)
end.
end.

If there's a better way to update each record, I'm fine with it--hopefully the general idea is pretty clear.
 
Note: If myfield is an index component use preselect instead of for each or it could cause real problems.

for each table:
if table.myfield matches "*|*"
then
table.myfield = substring(table.myfield,1,index(table.myfield,"|") - 1).
end.
 

LarryD

Active Member
Code:
for each table exclusive-lock:
if num-entries(table.myfield,"|") > 1 then do:
  assign table.myfield = entry(1,table.myfield,"|").
end.
end.

other possibliities exist (using alternate buffer, include the if then in a where clause, etc), but this is a quick and dirty.
 

tamhas

ProgressTalk.com Sponsor
Entry() is the operator you want for picking off the first piece.

Some people use the assign always since it is always implied.
 
Top