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

176
Views
Get the value from a string as key value pair

I have a string that looks like this. Thi string is taken from a file where each of the keys are in different lines.

languagesKnown = 'Mother-Tongue : Spanish OtherLanguages: English Major: German' 

It can also look like

languagesKnown = 'Mother-Tongue:   OtherLanguages: English Major: German' 

I want to check which value is set to Mother-Tongue.

content:string[] = languagesKnown..split('\n')

gives me a string array, But I want to see if something is set to it or if it is empty like above.

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

0

try using split:

const examples = ['Mother-Tongue: Spanish OtherLanguages: English Major: German', 'Mother-Tongue:  OtherLanguages: English Major: German']
const values = examples.map(string => string.split(/[a-zA-Z-]*:/).slice(1))

for (value of values) {
  console.log(value[0].replace(/ /g, '') !== '')
}

about 4 years ago · Juan Pablo Isaza Report

0

With a regex you can easily find if there is a Mother Tongue and get its value.

let languagesKnown1 = 'Mother-Tongue : Spanish OtherLanguages: English Major: German';
let languagesKnown2 = 'Mother-Tongue:   OtherLanguages: English Major: German';

function getMotherTongue(languagesKnown){
    let regexMatch = languagesKnown.match(/Mother-Tongue : \w+/)
    if(regexMatch != null && regexMatch.length > 0)
      return regexMatch[0].split(":")[1].trim()

    return "No Mother Tongue!"
}

console.log(getMotherTongue(languagesKnown1))
console.log(getMotherTongue(languagesKnown2))
about 4 years ago · Juan Pablo Isaza Report

0

Try to split the string into an array of strings with : as the delimitier character.

The only problem could be the nonuniform formatting. So a solution could be counting the whitespaces. If there is more than 1 whitespace after a colon -> empty value.

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!