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

213
Views
How can I delete one part of the string without deleting the same set of characters in another place?

I'm trying to clean up a string (URL). I need that every time it contains ipfs://ipfs/ to replace it by a single ipfs/. The full string is ipfs://ipfs/QmR6xjBCn but it should be ipfs://QmR6xjBCn In some cases I get string that are already clean, in other cases I dont'.

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

0

I've used include to detect if the string contained ipfs://ipfs and then replaced it for what I needed: ipfs://

if (fixedURL.includes('ipfs://ipfs')) {
  fixedURL2 = fixedURL.replace('ipfs://ipfs','ipfs://')

  obj.imageUrl = fixedURL2;
} else {

  obj.imageUrl = fixedURL;
}
about 4 years ago · Juan Pablo Isaza Report

0

Use the replace() function. If the text is not in the string then it won't replace anything. So it only works when the double ipfs is there.

let str;
// example one
str = "ipfs://ipfs/QmR6xjBCn";
str = str.replace("ipfs://ipfs/","ipfs://");
console.log(str);

// example two, same code different url
str = "ipfs://SomethingRandom";
str = str.replace("ipfs://ipfs/","ipfs://");
console.log(str);

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!