web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Split string and speci...
Power Apps
Unanswered

Split string and special characters

(0) ShareShare
ReportReport
Posted on by 31

Hello,

I have a situation where I am splitting words from a text input control. I have all the words split into a collection with the first column being the row number and the second column being the word. So far so good. But then I noticed any special characters stay with the word. How can I also split any special characters to be their own row as well? For example....

 

Here is what I have now:

oPostNum      OriginalString

1                     Hi,

2                     How

3                    Are

4                    You

5                    Today?

 

This is what I need:

oPosNum       OriginalString

1                     Hi

2                     ,

3                    How

4                    Are

5                    You

6                    Today

7                     ?

 

The code I have at this point which gives me the output I listed first above....

 

 

 

ClearCollect(
 colOriginalStrings,
 RenameColumns(
 With(
 {
 records: Trim(
 Split(
 originaltext.Value,
 " "
 )
 )
 },
 ForAll(
 Sequence(CountRows(records)),
 Patch(
 Last(
 FirstN(
 records,
 Value
 )
 ),
 {oPosNum: Value}
 )
 )
 ),
 "Value",
 "OriginalString"
 )
)

 

 

 

 

Any help would be greatly appreciated!!

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @Deek 

     

    please try this:

     

    Clear(colOriginalStrings);
    ForAll(
     Split(originaltext.Value, " "),
     Collect(
     colOriginalStrings,
     {oPosNum: CountRows(colOriginalStrings) + 1, OriginalString: TrimEnds(Result, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")}
     ),
     ForAll(
     Split(TrimEnds(Result, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), ""),
     Collect(
     colOriginalStrings,
     {oPosNum: CountRows(colOriginalStrings) + 1, OriginalString: Result}
     )
     )
    );

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Deek Profile Picture
    31 on at

    Hey @mmbr1606 ,

    Thanks for the reply. The formula you gave me didn't work unfortunately. I had to change the Result to Value which cleared up some of the errors (no big deal, as it is tailoring, I expect to do). The other issue appears to be that the TrimEnds function only wants one argument, and we are giving it two arguments.

     

    If you have any other ideas, I am open to experiment for sure. I have brain cramped myself trying to figure this out lol.

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    try this:

     

    Clear(colOriginalStrings);
    Set(varCurrentWord, "");
    Set(varWordIndex, 1);
    
    ForAll(
     Mid(originaltext.Value, 1, Len(originaltext.Value)) As char,
     If(
     IsMatch(char, "[a-zA-Z0-9]"),
     Set(varCurrentWord, varCurrentWord & char),
     If(
     !IsEmpty(varCurrentWord),
     Collect(colOriginalStrings, {oPosNum: varWordIndex, OriginalString: varCurrentWord}),
     Set(varWordIndex, varWordIndex + 1),
     Set(varCurrentWord, "")
     ),
     If(
     !IsEmpty(char) && !IsBlank(char) && char <> " ",
     Collect(colOriginalStrings, {oPosNum: varWordIndex, OriginalString: char}),
     Set(varWordIndex, varWordIndex + 1)
     )
     )
    );
    
    If(
     !IsEmpty(varCurrentWord),
     Collect(colOriginalStrings, {oPosNum: varWordIndex, OriginalString: varCurrentWord})
    );

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Deek Profile Picture
    31 on at

    Sorry no dice. I have read through your code and can't find why it won't work. It makes sense to me. I am going to keep trying as well. If I come up with anything I will post it.

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    Clear(colOriginalStrings);
    Set(varCurrentWord, "");
    Set(varWordIndex, 1);

    // Iterate over each character
    ForAll(
    Mid(originaltext.Value, 1, Len(originaltext.Value)) As char,
    If(
    IsMatch(char.Result, "[a-zA-Z0-9]"),
    // Add to current word if it's a letter or number
    Set(varCurrentWord, varCurrentWord & char.Result),
    // If special character, end current word and add special character as new row
    If(
    !IsEmpty(varCurrentWord),
    Collect(colOriginalStrings, {oPosNum: varWordIndex, OriginalString: varCurrentWord}),
    Set(varWordIndex, varWordIndex + 1),
    Set(varCurrentWord, "")
    ),
    If(
    !IsEmpty(char.Result) && char.Result <> " ",
    Collect(colOriginalStrings, {oPosNum: varWordIndex, OriginalString: char.Result}),
    Set(varWordIndex, varWordIndex + 1)
    )
    )
    );

    // Add the last word if there is one
    If(
    !IsEmpty(varCurrentWord),
    Collect(colOriginalStrings, {oPosNum: varWordIndex, OriginalString: varCurrentword}))

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard