Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
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 Respuestas
Responde la pregunta

0

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

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda