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

143
Visualizações
How do you find the line number of a string in a byte array?

What I'm trying to find:

  • A function definition within a code file.

Information I have:

  • Code file.
  • The byte index of where the function definition starts in the code file and length in bytes.

How should I go about finding this function's line number in the file?

My current thoughts:

  • Read code file as byte array
  • Find function inside byte array by using start index and length for end.
  • Convert this function from binary to text.
  • Convert whole code file from binary to text.
  • Number the lines in the text.
  • Pattern match to find where the function is in the text and return line number.

I'm using Golang for the back-end service which I believe will execute this functionality. Though I also have a front-end in JavaScript which I can leverage to help if needed.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Would something like counting newline characters be good enough, or are you looking into something more tweaky?

You could just start counting newlines \n until you reach the byte index. The line number is the number of newline characters.

about 4 years ago · Juan Pablo Isaza Relatório

0

Assuming that you have the contents of the file p as type []byte and the byte index of the function as int i, then bytes.Count(p[:i], []byte{'\n'}) + 1 returns the line number for the function.

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