Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Assoc ReplaceAll(String input, String patturn, String replace)
- Assoc retVal
- retVal.ok = false
- retVal.ErrMsg = Undefined
- retVal.ApiError = Undefined
- retVal.Input = input
- retVal.Pattern = patturn
- retVal.Replace = replace
- retVal.Output = Undefined
- String output = Undefined
- PatFind finder
- List result
- Integer start
- Integer stop
- String match
- if ( (IsDefined(input)) && (Length(input)>0) )
- finder = Pattern.CompileFind( patturn )
- if (IsError(finder))
- retVal.ErrMsg = Str.Format("%1", finder)
- retVal.ApiError = finder
- else
- output = ""
- result = Pattern.find(input, finder)
- if (IsDefined(result))
- while(IsDefined(result))
- start = result[1]
- stop = result[2]
- match = result[3]
- if (start >1)
- output += input[:start-1]
- end
- output += replace
- input = input[stop+1:]
- result = Pattern.find(input, finder)
- if (IsUndefined(result))
- output += input
- end
- end
- retVal.ok = true
- retVal.Output = output
- else
- retVal.ok = true
- retVal.Output = input
- end
- end
- else
- retVal.ok = true
- retVal.Output = input
- end
- if (!retVal.ok)
- if (IsUndefined(retVal.ErrMsg))
- retVal.ErrMsg = "Unknown error while trying to execute ReplaceAll."
- end
- end
- return retVal
- end
Add Comment
Please, Sign In to add comment