Kbase P140154: Sample code to locate a pattern which appears randomly in a free text format long char.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  17/03/2009 |
|
Status: Unverified
GOAL:
Sample code to locate a pattern which appears randomly in a free text format long char.
GOAL:
Which function can be used to locate the index of a pattern which appears randomly in a free text format long char?
FACT(s) (Environment):
Windows
Progress 9.x
OpenEdge 10.x
FIX:
Index function returns an integer that indicates the position of the target string within the source string.
Syntax:
INDEX (source, target [ , starting] )
Sample code:
DEFINE VARIABLE cText AS CHAR.
DEFIN VARIABLE cTemp AS CHAR.
DEFINE VARIABLE cPO AS CHAR.
DEFINE VARIABLE iPos AS INTEGER.
DEFINE VARIABLE iLength AS INTEGER.
ASSIGN cText = "asb PO:TPAG32956 CO:KMT0070 LC NO:DC".
iPos = INDEX (cText, "PO:").
MESSAGE "PO: starting index is:" iPos VIEW-AS ALERT-BOX.
cTemp = SUBSTRING ( cText, iPos, -1,"CHARACTER").
MESSAGE "Temp String is:" cTemp VIEW-AS ALERT-BOX.
iPos = INDEX (cTemp, " ").
MESSAGE "Space index after PO: is" iPos VIEW-AS ALERT-BOX.
ASSIGN iLength = iPos - 3.
MESSAGE "PO Number length is" iLength VIEW-AS ALERT-BOX.
cPO = SUBSTRING (cTemp, 4,iLength,"CHARACTER").
MESSAGE "PO: is" cPO VIEW-AS ALERT-BOX.