Insert a semi-colon every ten numbers

You may also like...

5 Responses

  1. thomas says:

    Hi Sancho,
    I appreciate your wonderful blog post.
    My suggested solution would be the following:
    Coalesce(Concat(MatchAll(inpStr.Text, “\d{10}”), FullMatch, “;”), “”)

    • iAm_ManCat says:

      Thanks for suggesting a solution Thomas, I have appended yours to the bottom of the blog!
      It works, but it does assume the user will be perfect at typing/pasting in the numbers in exact 10-number blocks

      • thomas says:

        I have changed the formula slightly to include non-numeric values.
        The disadvantage is that the formula can thus no longer be used in non-behavior properties.

        Set( _resultStr,
        Coalesce(
        // create string with 10 digits followed by a semicolon for all rows
        Concat(
        // create table with always 10 digits in a row
        MatchAll(
        // rebuild the string with only numeric values in it
        Concat(
        // remove all non numeric values
        RemoveIf(
        // split string into table with single characters
        Split(inpStr.Text, “”),
        // finding the value in the string
        IsBlank(Find(Result, “0123456789”))
        ),
        Result
        ),
        “\d{10}”
        ), FullMatch, “;”
        ),
        “”
        )
        );

        • iAm_ManCat says:

          That’s fantastic – thank you for sharing! I have amended the article to reflect the new code – it covers all edge cases I can think of and is more efficient 🙂

          • thomas says:

            There is always room for improvement… 😉
            If the number of digits found is not divisable by 10, an error will be thrown.

            Set( _resultStr,
            IfError(
            With(
            {
            numStr:
            Concat(
            Split(inpStr.Text, “”),
            If(IsMatch(Result, “[0-9]”), Result)
            )
            },
            If(Mod(Len(numStr), 10) = 0,
            Concat(
            MatchAll( numStr, “\d{10}”),
            FullMatch, “;”
            ),
            // throw error – will be catched by IfError()
            Error({ Kind: ErrorKind.Validation, Message: “the number of digits found is not divisable by 10.” })
            )
            ),
            // handle error
            Notify($”Please check incoming string: {FirstError.Message}”, NotificationType.Error);
            SetFocus(inpStr);
            “”
            )
            );

Leave a Reply

Your email address will not be published. Required fields are marked *