Replace text in simple string

Hello,

Why the simple replace text is not working as expected? I am trying to get the current script file name without extension.

put my name into scriptName
put 1st item of scriptName split by ".script" into scriptName
Log scriptName  ---prints ["Hello1", "<SELECTION>"]

--Tried like below too
put my name without extension
put my name with no extension
put my name with noextension

--delete too
put my name into scriptName
delete".script" from scriptName
Log scriptName  ---prints "Hello1<SELECTION>"

--replace
put my name into scriptName
replace ".script" in scriptName with empty 
Log scriptName  ---prints "Hello1<SELECTION>"

Any idea how I can achieve simple replace? Appreciate any help.

Hi. I’m a new user so I like to see how other people are using Eggplant. Your examples worked for me.

12/11/23, 3:41:14 PM START Running Selection from Sandbox2.script

03:41:14 Start handler 1: sandbox2
put my name into scriptname
replace “.script” in scriptName with empty
Log scriptName —prints “Hello1”
12/11/23, 3:41:14 PM Log Sandbox2
<<< 03:41:14 End handler 1: sandbox2 (normal exit)
Selection Executed in 0:00:00

But perhaps you didn’t want the after the script name? I added this to one of your examples.

put my name into scriptname
replace “.script” in scriptName with empty
Put scriptname into noextension
delete “Selection” from noextension – Selection is in the brackets but conflicts with the markup here.
log noextension

Thanks for the reply.

I am wondering why we have to keep on doing multiple things just like you mentioned by doing delete again followed by replace. Just simple delete or simple replace or any other single command should do the job.

It’s so complicated for even the people who have some background of coding or knowledge of any programming.

Wow I didn’t even know about “my name”. I have been getting my current script through a way more complicated method:

//The below code block determines the name and location of the login call script used (this script) and assigns it to a suitevariable.
//This allows users to programmatically call the script again if a need arises to login again (like when switch user kicks you out of SF
//The below code block MUST exist WITHIN the login call script itself (or you can code hardcode it if you prefer).
put (the last item of the callstack).scriptobjectID into Login_Call_Path
delete suiteinfo().scriptsfolder&“/” from Login_Call_Path
delete “” from Login_Call_Path
set the suitevariables.Login_Call_Path_SV to Login_Call_Path
Log “The name and location of my login call script is:”&&the suitevariables.Login_Call_Path_SV

Not quite the same thing you guys are talking about, but thanks for the tip.

How about this?

Log short name of file my name

Or even shorter:

Log short name of file me
3 Likes

Thanks for the tip. This helps in this situation.

Still my replace question remains. Hope some Eggplant staff will provide an answer.

I am not certain why you wanted to use replace, so I may be missing something.

The issues that you are running into begin with split. If you want to use it, just split on the period like this:
put the first item of (my name split by period) into myScriptName // sets the value of myScriptName to the value to the left of the period in the name of the calling script

Alternatively you could do this:

put my name into myScriptName
delete ".script" from myScriptName

Perhaps more basically, the issue is that you are not running the whole script but just a selection within it. That is why <SELECTION> keeps cropping up.

Hope this helps.
Dave

Thanks @DaveHester .

Yes, My point is not just for this case. If I have to do any simple replace, I would think like exactly you mentioned:

put my name into myScriptName
delete ".script" from myScriptName
--OR   replace ".script" with "abcd" in myScriptName
Log myScriptName ---Line#3

But If I get the myScriptName in line 3, still I am getting part of that. This is really confusing. If I run these 3 lines of script, I should get the expected text by replacing it or deleting it right? Am I missing anything?

I think it would be easiest to see if you added
Log myScriptName
to Line 2. You will see that the log will be different if you use the Run button than if you use the Run Selection button. I don’t think that the issue is with the replace; the issue is with my Name. My Name will return the script name if you are running the whole script. If you are running a selection from the script, it will return the script name with selection appended to the end.

1 Like

OMG :slight_smile: Got it now. Thanks.