Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda