Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
Nodejs splitting string
let NewName= params.strdocumentname + "(" + results.rows[0].arrayfilecount+ ")";
strdocumentname = params.strdocumentname = NewName;

the current output is Jayson.png(2)

desired output Jayson (2).png

How do i do that using the code above?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use the following code:-

const path = require('path');
const extension= path.extname(params.strdocumentname);
const name= params.strdocumentname.replace(extension,"(" + results.rows[0].arrayfilecount+ ")");
const newName = name + extension;

Hope it helps Thanks

about 4 years ago · Juan Pablo Isaza Report

0

I think your params.strdocumentname contains the extension of the file also. Try this code;

let [fileName, extension] = params.strdocumentname.split('.');
let NewName= fileName + "(" + results.rows[0].arrayfilecount+ ")." + extension;
strdocumentname = params.strdocumentname = NewName;

see working fiddle

let mockFileName = "abc.png"
let mockArrayCount = '1'

let [fileName, extension] = mockFileName.split('.');
let NewName= fileName + "(" + mockArrayCount+ ")." + extension;

console.log(NewName)
alert(NewName)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!