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

194
Visualizações
Javascript extract string from start to 0/, removing anything after 0/

I have a string which looks like this:

file:///storage/emulated/0/Pictures/IMG212.jpg

I want to remove anything from Pictures onwards so I would get this:

file:///storage/emulated/0/

How can I do this?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

var regex = /^.*0\//
var matches = str.match(regex);
console.log(matches[0]);
about 4 years ago · Juan Pablo Isaza Relatório

0

You could find the index of /0 and use substring to select everything up to that point, like so:

const line = "file:///storage/emulated/0/Pictures/IMG212.jpg";

// Get the location of "/0", will be 24 in this example
const endIndex = line.indexOf("/0");

// Select everything from the start to the endIndex + 2
const result = line.substring(0, endIndex+2);

The reason why we add +2 to the endIndex is because the string that we're trying to find is 2 characters long:

file:///storage/emulated/0/Pictures/IMG212.jpg
                  [24]--^^--[25]
about 4 years ago · Juan Pablo Isaza Relatório

0

You can split the string using split method:

const myString = "file:///storage/emulated/0/Pictures/IMG212.jpg";
const result = myString.split("0/")[0] + "0/";
console.log(result);    // file:///storage/emulated/0/

documentation for split method on MDN

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