A utilidade retorna os valores desejados do texto e exibe múltiplos valores, se existirem, com base na string de início e na string de término.
Class Test.Utility.FunctionSet Extends %RegisteredObject
{
/// W !,##class(Test.Utility.FunctionSet).ExtractValues("Some random text VALUE=12345; some other VALUE=2345; more text VALUE=345678;","VALUE=",";")
ClassMethod ExtractValues(text As %String, startStr As %String, endStr As %String) As %String
{ //Initialize Valriables
Set values = ""
Set start = 1
While start '= 0 {
Set start = $FIND(text, startStr, start)
IF start = 0 { QUIT }
Set end = $FIND(text, endStr, start)
IF end = 0 { QUIT }
//S value = $E(text, start, end-2)
S value = $E(text, start, end-$L(endStr)-1)
IF values '= "" {
Set values = values _" "_value
}Else {
S values = value
}
S start = end
}
Q values
} }
Output:
W !,##class(Test.Utility.FunctionSet).ExtractValues("Some random text VALUE=12345; some other VALUE=2345; more text VALUE=345678;","VALUE=",";")
12345 2345 345678