Removing the first two characters in a string
Hi,
This must be a really easy question but for some reason I am unable to do this
I have a string name = "ERRORMSG"
I want to remove the first 2 characters in the string, so the result should be string newname = RORMSG
Please can you advice on how I can do this?
set name=$Extract(name,3,*-1)
set name = "ERRORMSG"
set name = $E(name,3,$L(name))
Hi Sean, thank you for replying to my request. Using the above code, I am getting just RORMS, I am not getting the last character.
$e(name,3,*-0) worked.
Thank you so much. I am grateful
Thank you Pavel,
I like this one ^^
Cheers,
Jacques
This answer by Pavel is the simplest way. :)
$E(name,3,*-0)
Why "-0"?
Just "*" will be enough:
you can get a full list of these type of functions here...
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_FUNCTIONS
and a bit more information specifically on working with strings here...
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_strings
Hello,
There is several method to do so... depending of the context of your needs... if your error msg is at the beginning of the line, in the input text or alone...
You can use extract:
see: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...
this method would not be used if your input string does not start with "ERRORMSG"
if you know exactly that you want to remove ER from ERRORMSG you can use $replace
see: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...
you can use a $piece : https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...
Though this last method would have a problem is the string "ER" is repeated in the input string
I hope this help
Cheers,
Jacques
Also this option is available :
set $extract(name,1,2)=""
Perhaps tricky for someone :-)
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue