Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda