Last active
September 17, 2023 05:53
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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