Skip to content

Instantly share code, notes, and snippets.

@guibranco
Last active September 17, 2023 05:53
Show Gist options
  • Save guibranco/794921b44e5575558c631c1cb92177b7 to your computer and use it in GitHub Desktop.
Save guibranco/794921b44e5575558c631c1cb92177b7 to your computer and use it in GitHub Desktop.
Generates the barcode of a bank slip (pt-br: Boleto bancário) from typeful line (linha digitável)
/// <summary>
/// Calculates the bar code.
/// </summary>
private string CalculateBarCode(string typefulLine)
{
var line = Regex.Replace(typefulLine, "[^0-9]", "");
if (line.Length < 47)
{
line = line + new string('0', 47 - line.Length);
}
return line.Substring(0, 4)
+ line.Substring(32, 15)
+ line.Substring(4, 5)
+ line.Substring(10, 10)
+ line.Substring(21, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment