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

196
Views
How to split a string input that uses the same separator for items and their values

I've a text msg in which I've to format the values based on the time and then save it to the excel file. I tried with spilt and join function but it has new line so its not working.Is there any way to do it in javascript?

mytext:

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

mycode.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

Assuming that the received data has the same delimiter for seprating entries and for separating fields (of each entry) you can still parse the input reliably because you know that each entry always has 3 fields.

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!