Class ObjectScript.Examples
{
ClassMethod Conversions()
{
write !, "abcde becomes: ", $translate("abcde", "ad", "yz") // translate a->y, and d->z
write !, "abcde becomes: ", $translate("abcde", "ad", "zz") // translate a->z, and d->z
write !, "abcde becomes: ", $translate("abcde", "ad", "z") // translate a->z, and d->nothing
write !, "abcdebcbc becomes: ", $translate("abcdebcbc", "abc", "yz") // translate a->y, b->z, and c->nothing
write !, "abcdebcbc becomes: ", $replace("abcdebcbc", "abc", "yz") // replace abc->yz
read !, "String to translate: ", x
set lower = "abcdefghijklmnopqrstuvwxyz"
set upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
write !, "Using $translate: ", $translate(x, lower, upper)
write !, "Using $zconvert: ", $zconvert(x, "U")
write !, "Using $zconvert for capitalizing words: ", $zconvert(x, "W")
write !, "Using $zstrip to remove whitespace: ", $zstrip(x, "*W")
}
}
USER>do ##class(ObjectScript.Examples).Conversions()
abcde becomes: ybcze
abcde becomes: zbcze
abcde becomes: zbce
abcdebcbc becomes: yzdezz
abcdebcbc becomes: yzdebcbc
String to translate: the quick brown fox jumps over the lazy dog
Using $translate: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
Using $zconvert: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
Using $zconvert for capitalizing words: The Quick Brown Fox Jumps Over The Lazy Dog
Using $zstrip to remove whitespace: thequickbrownfoxjumpsoverthelazydog
USER>