How to trim (or cut or truncate) strings?

On one of my pages, I’m trying to display filenames of documents (uploaded in database). The documents are stored in a field called "message1_doc’. This field is marked as Document datatype.
I’ve tried using both Buttons as well as Text boxes to publish the same. However, they’re both indicating the entire path of Wix storage (which is prefixed by Wix themselves).

Example for button:

$w(“#dataset1”).onReady(() => {
$w(‘#doc1button1’).label = $w(‘#dataset1’).getCurrentItem().message1_doc;
})

Example for text box:

$w(“#dataset1”).onReady(() => {
$w(‘#doc1filename’).text = $w(‘#dataset1’).getCurrentItem().message1_doc;
})

RESULT :
wix:document://v1/43838f_3434343434.docx/Test1.docx

Objective:
The objective is for the button or Text box to publish just the last part. i.e. “Test1.docx”

P.S. I don’t need both button as well as text box. Any one would suffice.

When you upload any file to Wix the name gets changed, see here for more info.
https://support.wix.com/en/article/request-customizing-document-file-names

As for the name on your document button, this is something that can be done without code.
https://support.wix.com/en/article/showing-and-hiding-the-file-title-on-a-document-button
https://support.wix.com/en/article/sharing-documents-on-your-site

$w('#doc1button1').label = $w('#dataset1').getCurrentItem().message1_doc.split('/').slice(-1)[0];

Thank you very much… I’m not well versed with the Document button but as far as I understand, that button is for the site owner to upload documents. Whereas I’m trying to get site users to upload a document and then I display a filename to indicate what they’ve uploaded. Having said that, I’ll continue to see if that would also work.

Wow. This worked for me. Thanks a ton!!

On a related note, any idea why this doesn’t work to retrieve filename of VIDEO datatype?
For some reason, even a simple statement (as below) doesn’t seem to work.

$w(’ #video1filename ‘).text = $w(’ #dataset1 ').getCurrentItem().message1_video.

I’m certain that I’m getting the element name and field name right.

@rishalsharma Are you sure that there is a current item in the dataset? Do you have the field key (not name, but key) correct?

You can try using a console.log($w(’ #dataset1 ').getCurrentItem()) statement to inspect the returned current item.