[Custom Teascript Syntax] Replace part of strings
Posted: Fri Jun 24, 2022 4:07 pm
I created two custom Syntaxes for string values that replace or remove part of the value.
replace(source, text, start, size)
Returns the text with the replaced part
source: The text source which will have the replaced part
text: The replaced part
start: the specified start where the part will be replaced (First character is 1)
size: the size of the part which will be replaced (inferior to 0 means the size will take the size of the replaced part)
Script
remove(source, start, size)
Returns the text with the removed part
source: The text source which will have the removed part
start: the specified start where the part will be removed (First character is 1)
size: the size of the part which will be removed
Script
replace(source, text, start, size)
Returns the text with the replaced part
source: The text source which will have the replaced part
text: The replaced part
start: the specified start where the part will be replaced (First character is 1)
size: the size of the part which will be replaced (inferior to 0 means the size will take the size of the replaced part)
Examples: show
Code: Select all
script replace(source as string, text as string, start as double, size as double, return string)
start -= 1
if size < 0 then size = len(text)
if start < 0 or start+size > len(source)
call debug("____REPLACE STRING ERROR____")
call debug("Out of bound place on string")
call debug("Start-end position: "&(start+1)&"|"&start+size)
call debug("Length text: "&len(source))
call debug("_____________________________")
else
return left(source, start)+text+right(source, len(source)-start-size)
end
end script Returns the text with the removed part
source: The text source which will have the removed part
start: the specified start where the part will be removed (First character is 1)
size: the size of the part which will be removed
Examples: show
Code: Select all
script remove(source as string, start as double, size as double, return string)
start -= 1
if size < 0 then size = 0
if start < 0 then start = 0
if start+size > len(source)
return left(source, start)
else
return left(source, start)+right(source, len(source)-start-size)
end
end script