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

192
Views
Javascript extrae la cadena desde el inicio hasta 0/, eliminando cualquier cosa después de 0/

Tengo una cadena que se ve así:

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

Quiero eliminar algo de Imágenes en adelante, así que obtendría esto:

 file:///storage/emulated/0/

¿Cómo puedo hacer esto?

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

0

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

0

Puede encontrar el índice de /0 y usar la substring para seleccionar todo hasta ese punto, así:

 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);

La razón por la que agregamos +2 al endIndex es porque la cadena que estamos tratando de encontrar tiene 2 caracteres de largo:

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

0

Puede dividir la cadena usando el método de split :

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

documentación para el método split en MDN

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!