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

205
Views
Cómo dividir una entrada de cadena que usa el mismo separador para elementos y sus valores

Tengo un mensaje de texto en el que debo formatear los valores según la hora y luego guardarlo en el archivo de Excel. Intenté con la función derramada y unida, pero tiene una nueva línea, por lo que no funciona. ¿Hay alguna forma de hacerlo en javascript?

mi texto:

 16:15 test1 success 17:05 test4 success 17:40 test4234 down 18:25 test322 success 19:10 test423 success 20:20 test123 down 21:05 test454 success 21:40 test4 success 22:40 test145 success 23:35 test1123 down 00:35 testxx success 20:20 test123 down 14:20 test126 down 13:20 test177 success

micódigo.js

 const data = '16:15 EURJPY-OTC PUT 17:05 USDJPY-OTC PUT 17:40 EURJPY-OTC PUT 18:25 EURGBP-OTC CALL 19:10 USDJPY-OTC PUT 20:20 USDJPY-OTC PUT 21:05 NZDUSD-OTC CALL 21:40 EURUSD-OTC CALL 22:40 USDJPY-OTC PUT 23:35 USDJPY-OTC PUT 00:35 NZDUSD-OTC CALL'; console.log(data.split('').join(','),'datataaaaa')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Suponiendo que los datos recibidos tengan el mismo delimitador para separar entradas y para separar campos (de cada entrada), aún puede analizar la entrada de manera confiable porque sabe que cada entrada siempre tiene 3 campos.

 function parseEntries(data) { const entries = [] const tokens = data.split(' ') // space is the delimiter for (let i = 2; i < tokens.length; i += 3) { entries.push({ time: tokens[i - 2], name: tokens[i - 1], status: tokens[i] }) } return entries } const data = '16:15 EURJPY-OTC PUT 17:05 USDJPY-OTC PUT 17:40 EURJPY-OTC PUT 18:25 EURGBP-OTC CALL' const entries = parseEntries(data) console.log(entries) entries.forEach(e => { // do whatever you need here with each entry // e.time // e.name // e.status })

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!