go to post Stuart Strickland · Nov 8, 2023 Thanks Dmitry I want to find any string in another string that could be a plain string, a $LIST, or a series of nested $LIST to any depth - basically an unkown structure. The string I'm searching in can be any size and the pieces can be any size. And I wan't to do a case insensitive search through a large amount of data and I want instant results. And I want to know the character positions of what was found. And I want the results in a human readable format. And just to make it hard, it has to run on everything from Caché version 5 upwards which means $LISTNEXT, $LISTVALID are not always available.
go to post Stuart Strickland · Nov 8, 2023 That would be fine if I was looking for the full element value as my search string. I'm looking for any occurance, full or part, in a lot of data. From the documentation: $LISTFIND searches the specified list for the first instance of the requested value. A match must be exact and consist of the full element value. Letter comparisons are case-sensitive. Numbers are compared in canonical form. If an exact match is found, $LISTFIND returns the position of the matching element. If value is not found, $LISTFIND returns a 0. // Suppose the string I'm looking in is in S X=$LB("Stuart Strickland","Yaron Munz") // X could be anything // and I'm looking for "MUNZ" I $zcvt(X,"u")["MUNZ" Q 1 // I think this is quick but could cause a problem by converting lower case $LIST spacers to upper S sc=0 F i=1:1:$LL(X) S Y=$LG(X,i) I $zcvt(Y,"u")["MUNZ" s sc=1 // I think this is slow S sc=$LISTFIND(X,"MUNZ") // I know this will not work S sc=$LISTFIND($zcvt(X),"MUNZ") // I know this will not work and might even cause an error Q sc
go to post Stuart Strickland · Oct 23, 2023 132 ClassMethod Calendar(y As %Integer) As %String{q $p("Metal7Water7Wood7Fire7Earth",7,y#10\2+1)_" "_$p("Monkey7Rooster7Dog7Pig7Rat7Ox7Tiger7Rabbit7Dragon7Snake7Horse7Goat",7,y#12+1)}
go to post Stuart Strickland · Aug 3, 2023 Team effort. Credit where it is due, @Julius Kavay introduced the nested $TR, I changed his "" to a single character that didn't need a quote.
go to post Stuart Strickland · Aug 3, 2023 That article is an interesting read for anyone who has written code that goes directly to the generated INT code. I will need to re-think some of my older code that finds lines of code from $ZE and then displays and diagnoses the source of errors based on the variable names it finds there. I might also have to start using a mainstream debugger.
go to post Stuart Strickland · Aug 2, 2023 Ah yes, $Change can save a character on $Replace. And nested $TR saves on $zstrip. f{s z=x,x=$change($tr(x,$tr(x,"()")),"()",9) ret:x=z x=""}
go to post Stuart Strickland · Aug 2, 2023 //57? ClassMethod IsValid(s As %String) As %Boolean { q +$$zTestSearchString^%iFind.Utils.1($$$URLENCODE(s)) }
go to post Stuart Strickland · Aug 1, 2023 You are correct. implementation.size sees $c(13,10) as the end of line character. I counted manually and added 1, not 2.
go to post Stuart Strickland · Jul 28, 2023 61 bytes. Could an AI machine ever beat a human at code golf? Don't they just use brute force? ClassMethod IsValid(x){ f{s z=x,x=$replace($tr(x,$tr(x,"()")),"()",9) ret:x=z x=""}}
go to post Stuart Strickland · Jul 28, 2023 Class codeGolf.ParenthesisHell { ClassMethod IsValid(s As %String) As %Boolean { f{s t=s,s=$replace(s,"()","") ret:t=s s=""} }
go to post Stuart Strickland · Jul 14, 2023 I found a work around for it. Not perfect but it will do S RTN=$ZU(96,9) // or $SYSTEM.Process.CallingRoutine() which is identical in this situation I RTN="" F I=$ZU(41):-1:1 S RTN=$P($ZU(41,I),"^",3) I RTN'=$T(+0) Q:RTN'=""
go to post Stuart Strickland · Jul 13, 2023 It appears to only work intermittently from "D zzpp". If I ZLOAD another routine then go back and ZLOAD the first one, then it doesn't work. But if I issue an argumentless ZSAVE followed by "d zzpp" it works again.
go to post Stuart Strickland · May 19, 2023 I agree, but that was to make it work with the unit tests that were provided!
go to post Stuart Strickland · May 18, 2023 38, not good if the strings will never match ClassMethod Rotations(a As %String, b As %String) As %Integer { f i=0:1 ret:a=b i s b=$e(b,2,*)_$e(b) }