jimerb
February 26, 2022, 11:23pm
1
I'm looking to retrieve with javascript the leftmost part of a filename after the first period.
For example, if the selected file is
honda.2020.accord.txt
I'd like to have honda pre-populated in the dialog box that is called with a Getstring:
var dlg = clickData.func.Dlg();
var st = dlg.GetString('Collection Name:', st);
Can you point me in the right direction? I just spent time searching for this as well as trying to find the needed functionality in the manual.
Thanks.
lxp
February 27, 2022, 7:00am
2
You are looking for Javascript string manipulation. You'll find little in the Opus manual, but plenty on the web:
https://www.google.com/search?q=javascript+the+leftmost+part+of+a+filename+after+the+first+period
Would be a good example to learn a bit of regex, if that's on your bucket list
jimerb
February 27, 2022, 1:07pm
3
Thanks for that. I should be able to work with the string. How do I fetch the selected file name into a variable with a JavaScript?
lxp
February 27, 2022, 1:45pm
4
The default script in a button (and probably 99% of all scripts in the forum) provides an example.
jimerb
February 27, 2022, 4:12pm
6
Ok the default script got me going. Thanks for that.
Now I'm running into a error trying parse a string:
***Object doesn't support this property or method (0x800a01b6)***
I found this four year Old Forum Post that outlines this. I'm wondering if indexof still isn't naively supported?
Trying to find the first "." in the string:
var testme = "hello.22.22";
DOpus.Output(testme.indexof(".",1));
Leo
February 27, 2022, 4:49pm
7
Microsoft haven't updated JScript in a long time, and probably never will as they've abandoned it (despite not replacing it with anything, sigh), so the old information still applies to JScript today.
1 Like
lxp
February 27, 2022, 6:14pm
8
I found this four year Old Forum Post
You went a bit too far - going back two days would have been enough .
Can you spot the difference?
jimerb
February 27, 2022, 7:28pm
9
Oh geez. Thank you LXP!
I MUST get better at this.
String(item.realpath).indexOf(st)