cancel
Showing results for
Did you mean:
Impactful Individual

## insert a semi colon after every 10 digits

I have a textbox.

If someone copys and paste numbers into this textbox i need to insert a Semi colon after every 10th digit

i.e.

1421836968 1426031888 1426333858 1426110561 1426419152 1426316934 1426313930 1421800000 1456473342

becomes

1421836968;1426031888;1426333858;1426110561;1426419152;1426316934;1426313930;1421800000;1456473342

Thanks

fordraiders

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

@DAVIDPOWELL

I wrote a blog off the back of this, explaining my train of thought as I went through each step of this figuring it out - I also managed to get a better solution working that's neater.

You can set your Text Input (the actual one that takes in the text from the user) to have an OnChange of:

``````Set(
gblOriginalTextValue,
With(
{
CharacterString:
Concat(
Split(YourTextInput.Text,""),
If(
//If this item matches a digit
IsMatch(Result,
//here's where our regex goes
"[0-9]"
),
//Then use that value
Result
)
)
},
With(
{
//Getting the number of valid characters to iterate through
NumberOfValidCharacters: Len(CharacterString)
},
With(
{
//We split the valid string into characters
// then take the character (Result)
ValidCharacterArray: Split(CharacterString,"")
},
Concat(
ForAll(
Sequence(NumberOfValidCharacters),
//Thing that happens for every item
//We Take the FirstN Characters
//Then we get the Last of that
Last( FirstN( ValidCharacterArray, Value ) ).Result
&
//Check if we are on the tenth character
// by dividing by 10 and checking for the modulus (remainder)
If(
Mod(
ThisRecord.Value,
10
) = 0
&&
//Only add ; if this item is also not the last character
!(
ThisRecord.Value=NumberOfValidCharacters
),
";",
""
)
),
Value
)
)
)
)
)``````

Then set the Default property of that same Text Input control to:

``gblOriginalTextValue``

Cheers,

Sancho

 @iAm_ManCat My blog

 Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you! Thanks! You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy Sancho Harker, MVP
11 REPLIES 11
Super User

@DAVIDPOWELL, Your can use this formula:

``Concat(Split(TextInput1.Text," "),ThisRecord.Result&";")``

 If my reply helped you, please give a 👍 , & if it solved your issue, please 👍 & Accept it as the Solution to help other community members find it more. I am primarily available on weekdays from 6-10 PM CT and 5-10 PM CT on weekends. Visit my Blog: www.powerplatformplace.com

Super User

Hi @DAVIDPOWELL ,

Alternatively to the solution suggested by @AhmedSalih , you can use the Substitute function to substitute spaces with semicolons:

``Substitute(TextInput1.Text, " ", ";")``

Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.
Impactful Individual

Thanks, What "property/method" does this go under ?

Impactful Individual

tried both formulas under "On Change"

(these are not datacard objects). unbound textboxes

I do not see this addressed ?  the space will not always be there.

"insert a semi colon after every 10 digits"

Super User

@DAVIDPOWELL, you need to use the formula in the Default property of the InputText control.

Impactful Individual

I added a second textbox and put the formula in the Default property..

But i still need the formula to not assume i'm going to have a "SPACE"

I need:

insert a semi colon after every 10 digits

Super User

Looking at the screenshot you posted, its not just spaces, you've set up a multi-line text field, so you can have carriage return and line feed characters as well, also looks like you have double spaces... that's quite a challenge!

However, all of the above conditions don't really matter if we instead just take out everything else except the numbers, split that into rows, add row numbers, then after every tenth we insert a semi-colon.

To do this,

The OnChange of your txt_OrderNumbers control becomes:

``Set(gblOldText, Self.Text)``

Then the Default property of the txt_OrderNumbers control becomes:

``````Concat(
ForAll(
ForAll(
Sequence(
CountRows(
Split(
Concat(
Split(
gblOldText,
""
),
If(
IsMatch(
Result,
"[0-9]"
),
Result
)
),
""
)
)
),
{
ThisNum: Last(
FirstN(
Split(
Concat(
Split(
gblOldText,
""
),
If(
IsMatch(
Result,
"[0-9]"
),
Result
)
),
""
),
Value
)
).Result,
ThisRowNum: Value
}
),
ThisRecord.ThisNum & If(
!(ThisRowNum = 0) && Mod(
ThisRecord.ThisRowNum,
10
) = 0,
";",
""
)
),
Value
)``````

If you are wondering why we have to move the original text to a variable, this is to avoid the circular reference caused by referencing itself.

I have included a proof of concept app you can download and check for yourself 🙂

Cheers,

Sancho

 @iAm_ManCat My blog

 Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you! Thanks! You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy Sancho Harker, MVP
Super User

@DAVIDPOWELL

I wrote a blog off the back of this, explaining my train of thought as I went through each step of this figuring it out - I also managed to get a better solution working that's neater.

You can set your Text Input (the actual one that takes in the text from the user) to have an OnChange of:

``````Set(
gblOriginalTextValue,
With(
{
CharacterString:
Concat(
Split(YourTextInput.Text,""),
If(
//If this item matches a digit
IsMatch(Result,
//here's where our regex goes
"[0-9]"
),
//Then use that value
Result
)
)
},
With(
{
//Getting the number of valid characters to iterate through
NumberOfValidCharacters: Len(CharacterString)
},
With(
{
//We split the valid string into characters
// then take the character (Result)
ValidCharacterArray: Split(CharacterString,"")
},
Concat(
ForAll(
Sequence(NumberOfValidCharacters),
//Thing that happens for every item
//We Take the FirstN Characters
//Then we get the Last of that
Last( FirstN( ValidCharacterArray, Value ) ).Result
&
//Check if we are on the tenth character
// by dividing by 10 and checking for the modulus (remainder)
If(
Mod(
ThisRecord.Value,
10
) = 0
&&
//Only add ; if this item is also not the last character
!(
ThisRecord.Value=NumberOfValidCharacters
),
";",
""
)
),
Value
)
)
)
)
)``````

Then set the Default property of that same Text Input control to:

``gblOriginalTextValue``

Cheers,

Sancho

 @iAm_ManCat My blog

 Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you! Thanks! You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy Sancho Harker, MVP
Impactful Individual

First Thank you very much for the extreme extra effort to solve this issue !

I completely forgot about the carriage returns.

Glad the blog can probably help other folks in problems involving this area.

Dave

Announcements