Hello mates !
I'm trying to create a script into a business process to check the SIRET (French Enterprise Number). But I'm having a basic problem: an identifier is expected when I try to compile on line 59
using System.Text.RegularExpressions;
string siretNumber = Get<String>("siret");
bool siretValide = Get<bool>("siretValide");
int ttlAddition = 0, cpt = 1;
string formatInput = Regex.Replace(siretNumber, "[^a-zA-Z0-9_]+", "", RegexOptions.Compiled);
string reverseCard = new string(formatInput.ToCharArray().Reverse().ToArray());
int[] arrDigits = Array.ConvertAll<string, int>(
System.Text.RegularExpressions.Regex.Split(reverseCard.ToString(), @"(?!^)(?!$)"),
str => int.Parse(str)
);
int[] arrMult = new int[arrDigits.Length];
// First Luhn step:
// Start with the last digit (on the right)
// and move to the left, doubling the value of all even-numbered digits
for (int i = 0; i < arrDigits.Length; i++)
{
if (cpt == 1)
arrMult[i] = arrDigits[i]; // the key is processed first, the number is not doubled
else
{
if (cpt % 2 == 0)
arrMult[i] = 2 * arrDigits[i];
else
arrMult[i] = arrDigits[i];
}
cpt++;
}
// Add together all the digits of each number thus obtained.
// If digit > 10, then the digit to be added gives, for example: 18 = 1 + 8
for (int i = 0; i < arrMult.Length; i++)
{
if ((int)arrMult[i] >= 10) // if number > 9 you have to break down the number, e.g. 18 gives: 1+8
{
int[] intList = Array.ConvertAll<string, int>(
System.Text.RegularExpressions.Regex.Split(arrMult[i].ToString(), @"(?!^)(?!$)"),
str => int.Parse(str)
);
for (int j = 0; j < intList.Count(); j++)
{
ttlAddition += (int)intList[j];
}
}
else
ttlAddition += (int)arrMult[i];
}
// if modulo by 10 of the addition is zero then our figure is valid
if (ttlAddition % 10 == 0)
Set<bool>("siretValide", true); // set the variable siretValide to true in Creatio
else
Set<bool>("siretValide", false);
In VS Code, by replacing the last lines: Set<bool>("siret Valide", true);
with Console.WriteLine("Verification OK");
and Set<bool>("siret Valide", false);
with Console.WriteLine("Verification KO");
the program works fine.