Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

300
Vistas
¿Cómo encontrar similitudes entre una cadena de texto y una matriz?

Tengo una matriz de cadenas, que quiero comparar con una cadena de texto, si encuentra similitudes, quiero poder marcar en negro la similitud encontrada dentro de la cadena.

ejemplo:

 context.body: 'G-22-6-04136 - PatientName1' newBody: ['G-22-6-04136 - PatientName1' , 'G-22-6-04137 - PatientName2']

Al encontrar la similitud entre los dos, el resultado sería algo como esto

 newBody: [**'G-22-6-04136 - PatientName1'** , 'G-22-6-04137 - PatientName2']

¿Cómo podría hacerlo? ¿Es posible hacer esto? De antemano muchas gracias por la ayuda

 const totalSize: number = this.getSizeFromAttachments(attachments); const chunkSplit = Math.floor(isNaN(totalSize) ? 1 : totalSize / this.LIMIT_ATTACHMENTS) + 1; const attachmentsChunk: any[][] = _.chunk(attachments, chunkSplit); if ((totalSize > this.LIMIT_ATTACHMENTS) && attachmentsChunk?.length >= 1) { const result = attachment.map(element => this.getCantidad.find(y => element.content === y.content)) const aux = this.namePatient const ans = [] result.forEach(ele => { const expected_key = ele["correlative_soli"]; if (aux[expected_key]) { const newItem = { ...ele }; newItem["name_Patient"] = aux[expected_key] newItem["fileName"] = `${expected_key}${aux[expected_key] ? ' - ' + aux[expected_key] : null}\n`.replace(/\n/g, '<br />') ans.push(newItem) } }); let newBody: any; const resultFilter = attachment.map(element => element.content); const newArr = []; ans.filter(element => { if (resultFilter.includes(element.content)) { newArr.push({ fileNameC: element.fileName }) } }) newBody = `• ${newArr.map(element => element.fileNameC)}`; const date = this.cleanDateSolic; const amoung= attachmentsChunk?.length; const getCurrent = `(${index}/${attachmentsChunk?.length})` const header = `${this.cleanDateSolic} pront ${attachmentsChunk?.length} mail. This is the (${index}/${attachmentsChunk?.length})`; console.log('body', context.body); // context.body is the body I receive of frontend like a string const newContext = { newDate: date, amoung: amoung, getCurrent: getCurrent, newBody: newBody, ...context } return this.prepareEmail({ to: to, subject: ` ${subject} (Correo ${index}/${attachmentsChunk?.length})`, template: template, context: newContext, }, attachment); }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Según su ejemplo, parece que la cadena debe ser una coincidencia exacta, ¿es correcto?

Además, "márcalo en negrita" dependerá de lo que estés usando para representar esto, pero si solo quieres envolver la cadena en ** o <b> o lo que sea, podrías hacer algo como esto:

 newBody.map(str => str === context.body ? `**${str}**` : str);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Puede ver si existe una cadena en la matriz haciendo if arr.includes(desiredStr) //make text bold

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda