AnsweredAssumed Answered

String Searches

Question asked by VRFuser on May 11, 1998
Hi All,
I've developed a couple of VEE functions I thought might be worth
sharing. The attached program is written in HP VEE 4.01.

One function will locate and output the position(s) in a string of
*every* occurrence of a character - not just the first matching
character as with the strPosStr function.

The second function will search for a matching substring in a string
array and provide the array element (position) for every matching string
in the array.

Both of these functions use the comparator object. The comparator cannot
be used with strings, but the way around this is to convert your strings
to integers using the strPosStr function.

I did not have the time to convert this to VEE 3.21. If there is enough
interest, please let me know and I will provide a version in VEE 3.21 at
a later time.

Hope you find this useful,
John D. Seelbinder
Instrumentation Engineer
Eastman Kodak Company
mailto:L112656@kodak.com

-------------------------------------------------
(saveFormat "2.3")
(date "Tue 12/May/1998 11:03:11 ")
(veerev "4.01")
(platform "PC")
(execMode fast)
(filterNAN 0)
(workspaceStackingOrder M)
(SaveCF no)
(device 0 ROOTCONTEXT
(properties
(trigMode deg)
(nextID 17)
(popupTitleText "Untitled")
(popupMoveable 1)
(deleteGlobals 0))
(deviceList
(UserFunctions
(nextID 2)
(context 0
(properties
(name "findMultipleCharPos")
(trigMode deg)
(nextID 8)
(popupTitleText "UserFunction1")
(popupMoveable 1))
(interface
(input 1
(name "findChar")
(optional yes))
(input 2
(name "str")
(optional yes))
(output 1
(type data)
(name "charPos")
(lock constraints)
(optional yes)))
(deviceList
(device 0 FROMSTRING
(properties
(name "Convert to Char Ary")
(transactions 1 "READ TEXT x CHAR:1 ARRAY:*"))
(interface
(input 1
(name "AString")
(requires
(datatype Text))
(lock name constraints))
(output 1
(name "X")
(optional yes)))
(implementation
(attr iopath string read "string"
(readTerm "
")
(fs " ")
(eol "
")
(multiField fullSyntax)
(arrayFormat block))))
(device 1 FORMULA
(properties
(name "strPosStr")
(expr 1 "strPosStr(A, searchString)"))
(interface
(input 1
(name "searchString")
(optional yes))
(input 2
(name "A")
(optional yes))
(output 1
(name "Result")
(tag "Result")
(lock name constraints)
(optional yes))))
(device 2 CONSTANT
(properties
(name "Integer"))
(interface
(output 1
(name "Int32")
(lock name constraints)))
(implementation
(value Int32
(data  -1))
(initValue Int32
(data  0))))
(device 3 COMPARATOR
(properties
(relation ==))
(interface
(input 1
(name "Ref Value")
(tag "RefValue"))
(input 2
(name "Test Value")
(tag "TestValue"))
(output 1
(name "Passed")
(tag "Passed")
(lock name constraints)
(optional yes))
(output 2
(name "Failed")
(tag "Failed")
(lock name constraints)
(optional yes))
(output 3
(name "Failures")
(tag "Failures")
(lock name constraints)
(optional yes))))
(device 4 FROMCOORDINATE
(interface
(input 1
(name "Coord Data")
(requires
(datatype Coord))
(lock name constraints))
(output 1
(name "X Data")
(lock name constraints))
(output 2
(name "Y Data")
(lock name constraints)
(optional yes))))
(device 5 IFTHENELSE
(properties
(cases 1 "(totSize(A)==0 ? [-1] : 0)"))
(interface
(input 1
(name "A")
(optional yes))
(output 1
(name "Then")
(lock name constraints))
(output 2
(name "Else")
(lock name constraints))))
(device 6 JUNCTION
(properties
(name "JCT"))
(interface
(input 1
(name "A")
(lock name constraints))
(input 2
(name "B")
(lock name constraints))
(output 1
(name "Data"))))
(device 7 NOTE
(properties
(name "About findMultipleCharPos")
(text2 6 "This function will find and display"
"as an array, all of the position(s)" "in a string of a single
character." ""
"If no match is found, the function" "returns -1.")))
(configuration
(connect I2:1 D0:1)
(connect I1:1 D1:1)
(connect D0:1 D1:2)
(connect D2:1 D3:1)
(connect D1:1 D3:2)
(connect D5:2 D4:0)
(connect D3:3 D4:1)
(connect D3:3 D5:1)
(connect D5:1 D6:1)
(connect D4:1 D6:2)
(connect D6:1 O1:1)))
(contextCarrier
(active detail)
(detail
(extent 879 685)
(anchorPt -71 -22)
(configuration
(devCarrierFor 0
(active icon)
(icon
(extent 138 16))
(open
(extent 254 78))
(terminals on)
(pinCenter 370 510))
(devCarrierFor 1
(active icon)
(icon
(extent 63 25))
(open
(extent 235 41))
(terminals on)
(pinCenter 500 500))
(devCarrierFor 2
(active icon)
(icon
(extent 48 16))
(open
(extent 84 30)
(showFormat int))
(pinCenter 500 470))
(devCarrierFor 3
(active icon)
(icon
(extent 82 34))
(open
(extent 214 70))
(terminals on)
(pinCenter 590 490))
(devCarrierFor 4
(active icon)
(icon
(extent 100 52)
(iconImage "unbuild.icn"))
(open
(extent 21 50))
(terminals on)
(pinCenter 790 500))
(devCarrierFor 5
(active icon)
(icon
(extent 82 25))
(open
(extent 184 53))
(terminals on)
(pinCenter 730 440))
(devCarrierFor 6
(active icon)
(icon
(extent 29 25))
(open)
(terminals on)
(pinCenter 880 480))
(devCarrierFor 7
(active icon)
(icon
(extent 183 52)
(iconImage "notepad.icn"))
(open
(extent 315 191)
(editing enabled))
(pinCenter 550 390))
(connect I2:1 D0:1
(points 4 71 534 10 534 10 510 298 510))
(connect I1:1 D1:1
(points 4 71 194 10 194 10 490 466 490))
(connect D0:1 D1:2
(points 2 441 510 466 510))
(connect D2:1 D3:1
(points 4 526 470 540 470 540 480 546 480))
(connect D1:1 D3:2
(points 2 534 500 546 500))
(connect D5:2 D4:0
(points 3 773 450 790 450 790 471))
(connect D3:3 D4:1
(points 2 633 500 737 500))
(connect D3:3 D5:1
(points 4 633 500 650 500 650 440 686 440))
(connect D5:1 D6:1
(points 4 773 430 850 430 850 470 863 470))
(connect D4:1 D6:2
(points 2 842 490 863 490))
(connect D6:1 O1:1
(points 4 897 480 920 480 920 364 949 364)))
(stackingOrder 1 0 2 4 5 6 7 3))))
(context 1
(properties
(name "findStringsInArray")
(trigMode deg)
(nextID 7)
(popupTitleText "UserFunction1")
(popupMoveable 1))
(interface
(input 1
(name "findString")
(optional yes))
(input 2
(name "ary")
(optional yes))
(output 1
(type data)
(name "aryPos")
(lock constraints)
(optional yes)))
(deviceList
(device 0 CONSTANT
(properties
(name "Integer"))
(interface
(output 1
(name "Int32")
(lock name constraints)))
(implementation
(value Int32
(data  -1))
(initValue Int32
(data  0))))
(device 1 COMPARATOR
(properties
(relation ==))
(interface
(input 1
(name "Ref Value")
(tag "RefValue"))
(input 2
(name "Test Value")
(tag "TestValue"))
(output 1
(name "Passed")
(tag "Passed")
(lock name constraints)
(optional yes))
(output 2
(name "Failed")
(tag "Failed")
(lock name constraints)
(optional yes))
(output 3
(name "Failures")
(tag "Failures")
(lock name constraints)
(optional yes))))
(device 2 FORMULA
(properties
(name "strPosStr(str1,str2)")
(expr 1 "strPosStr(ary, findString)"))
(interface
(input 1
(name "findString")
(optional yes))
(input 2
(name "ary")
(optional yes))
(output 1
(name "Result")
(tag "Result")
(lock name constraints)
(optional yes))))
(device 3 FROMCOORDINATE
(interface
(input 1
(name "Coord Data")
(requires
(datatype Coord))
(lock name constraints))
(output 1
(name "X Data")
(lock name constraints))
(output 2
(name "Y Data")
(lock name constraints)
(optional yes))))
(device 4 IFTHENELSE
(properties
(cases 1 "(totSize(A)==0 ? [-1] : 0)"))
(interface
(input 1
(name "A")
(optional yes))
(output 1
(name "Then")
(lock name constraints))
(output 2
(name "Else")
(lock name constraints))))
(device 5 JUNCTION
(properties
(name "JCT"))
(interface
(input 1
(name "A")
(lock name constraints))
(input 2
(name "B")
(lock name constraints))
(output 1
(name "Data"))))
(device 6 NOTE
(properties
(name "About findStringsInArray")
(text2 7 "This function will find and display"
"as an array, all of the position(s)" "in an array of matching strings
or"
"substrings." "" "If no match is found, the function" "returns -1.")))
(configuration
(connect D0:1 D1:1)
(connect D2:1 D1:2)
(connect I1:1 D2:1)
(connect I2:1 D2:2)
(connect D4:2 D3:0)
(connect D1:3 D3:1)
(connect D1:3 D4:1)
(connect D4:1 D5:1)
(connect D3:1 D5:2)
(connect D5:1 O1:1)))
(contextCarrier
(active detail)
(detail
(extent 790 685)
(anchorPt -27 162)
(configuration
(devCarrierFor 0
(active icon)
(icon
(extent 48 16))
(open
(extent 84 30)
(showFormat int))
(pinCenter 410 250))
(devCarrierFor 1
(active icon)
(icon
(extent 82 34))
(open
(extent 214 70))
(terminals on)
(pinCenter 510 270))
(devCarrierFor 2
(active icon)
(icon
(extent 132 25))
(open
(extent 190 42))
(terminals on)
(pinCenter 310 280))
(devCarrierFor 3
(active icon)
(icon
(extent 100 52)
(iconImage "unbuild.icn"))
(open)
(terminals on)
(pinCenter 680 280))
(devCarrierFor 4
(active icon)
(icon
(extent 86 26))
(open
(extent 184 53))
(terminals on)
(pinCenter 620 210))
(devCarrierFor 5
(active icon)
(icon
(extent 29 25))
(open)
(terminals on)
(pinCenter 780 260))
(devCarrierFor 6
(active icon)
(icon
(extent 168 52)
(iconImage "notepad.icn"))
(open
(extent 315 191)
(editing enabled))
(pinCenter 490 120))
(connect D0:1 D1:1
(points 4 436 250 450 250 450 260 466 260))
(connect D2:1 D1:2
(points 2 378 280 466 280))
(connect I1:1 D2:1
(points 4 27 10 10 10 10 270 241 270))
(connect I2:1 D2:2
(points 4 27 350 10 350 10 290 241 290))
(connect D4:2 D3:0
(points 3 665 220 680 220 680 251))
(connect D1:3 D3:1
(points 2 553 280 627 280))
(connect D1:3 D4:1
(points 6 553 280 570 280 570 250 560 250 560 210 574 210))
(connect D4:1 D5:1
(points 4 665 200 750 200 750 250 763 250))
(connect D3:1 D5:2
(points 2 732 270 763 270))
(connect D5:1 O1:1
(points 4 797 260 820 260 820 180 816 180)))
(stackingOrder 1 0 2 5 3 4 6)))))
(device 0 LITERALCONSTANT
(properties
(name "Text"))
(interface
(output 1
(name "Text")
(lock name constraints)))
(implementation
(value Text
(data  "-test-string-"))
(initValue Text
(data  ""))))
(device 10 LITERALCONSTANT
(properties
(name "character search string"))
(interface
(output 1
(name "Text")
(lock name constraints)))
(implementation
(value Text
(data  "t"))
(initValue Text
(data  ""))))
(device 11 CALL
(properties
(name "Call findMultipleCharPos")
(callFunc "findMultipleCharPos")
(parmMode rev30))
(interface
(input 1
(name "findChar")
(optional yes))
(input 2
(name "string")
(optional yes))
(output 1
(name "charPos")
(lock name constraints)
(optional yes))))
(device 12 TEXTDISPLAY
(properties
(name "Char Positions"))
(interface
(input 1
(name "Data"))))
(device 13 CALL
(properties
(name "Call findStringsInArray")
(callFunc "findStringsInArray")
(parmMode rev30))
(interface
(input 1
(name "findString")
(optional yes))
(input 2
(name "ary")
(optional yes))
(output 1
(name "aryPos")
(lock name constraints)
(optional yes))))
(device 14 LITERALCONSTANT
(properties
(name "Text"))
(interface
(output 1
(name "Text")
(lock name constraints)))
(implementation
(value Text
(numDims 1)
(size 10)
(data  [ "String 1" "Second string" "Hello" "String 2" "string 2"
"Hewlett-Packard" "test" "May 1998" "alpha" "gamma" ]))
(initValue Text
(data  ""))))
(device 15 LITERALCONSTANT
(properties
(name "search string"))
(interface
(output 1
(name "Text")
(lock name constraints)))
(implementation
(value Text
(data  "string"))
(initValue Text
(data  ""))))
(device 16 TEXTDISPLAY
(properties
(name "Array Positions"))
(interface
(input 1
(name "Data"))))
(configuration
(connect D1:1 D2:1)
(connect D0:1 D2:2)
(connect D2:1 D3:1)
(connect D6:1 D4:1)
(connect D5:1 D4:2)
(connect D4:1 D7:1)))
(contextCarrier
(wndRestoredOrigin 2 2)
(wndRestoredExtent 856 685)
(wndState max)
(active detail)
(detail
(extent 1078 913)
(anchorPt -20 195)
(configuration
(devCarrierFor 0
(active open)
(icon)
(open
(extent 194 30))
(pinCenter 220 120))
(devCarrierFor 10
(active open)
(icon
(extent 160 0))
(open
(extent 196 30))
(pinCenter 490 70))
(devCarrierFor 11
(active icon)
(icon
(extent 169 25))
(open
(extent 196 53))
(terminals on)
(pinCenter 700 110))
(devCarrierFor 12
(active open)
(icon
(extent 101 0))
(open
(extent 137 239))
(pinCenter 890 110))
(devCarrierFor 13
(active icon)
(icon
(extent 154 25))
(open
(extent 196 53))
(terminals on)
(pinCenter 700 380))
(devCarrierFor 14
(active open)
(icon)
(open
(extent 263 174))
(pinCenter 220 390))
(devCarrierFor 15
(active open)
(icon
(extent 90 0))
(open
(extent 196 30))
(pinCenter 480 330))
(devCarrierFor 16
(active open)
(icon
(extent 104 0))
(open
(extent 140 239))
(pinCenter 890 380))
(connect D1:1 D2:1
(points 4 590 70 600 70 600 100 613 100))
(connect D0:1 D2:2
(points 2 319 120 613 120))
(connect D2:1 D3:1
(points 2 787 110 819 110))
(connect D6:1 D4:1
(points 4 580 330 600 330 600 370 620 370))
(connect D5:1 D4:2
(points 2 354 390 620 390))
(connect D4:1 D7:1
(points 2 779 380 817 380)))
(stackingOrder 3 2 1 5 6 7 4 0))
(numberFormats
(realFormat standard)
(realSigDigits 4)
(realRadixSpec 4)
(integerBase decimal))))

Outcomes