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

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Insert character in a ...
Power Apps
Answered

Insert character in a string field

(0) ShareShare
ReportReport
Posted on by 674

I have a table/collection in PowerApps where the strings are formatted like: WW031-231, DT031-222, etc. I would like to convert these by inserting a hyphen after the first two characters, to produce WW-031-231, DT-031-222, etc.

What is the simplest way to do this? Some combination of replace, substitute, split, LEN?

 

Thanks.

Categories:
I have the same question (0)
  • Verified answer
    SpongYe Profile Picture
    5,715 Super User 2026 Season 1 on at

    Hi @Runner55552 

     

    I used Set but use what you are more comfortable with:

    Set(OriginalString, "WW031-231");
    Set(FirstString, Left(OriginalString, 2));
    Set(SeconString, Mid(OriginalString, 3, 3)); 
    Set(ThirdString, Right(OriginalString, Len(OriginalString) - 6));
    Set(
     CombinedString, 
     Concatenate(FirstString, "-", SeconString, "-", ThirdString)
    )
    
    

    SpongYe_0-1708643097751.png

     

    If you have any questions or feedback, please let me know. Have a great day! 😊

    -----------------------
    PowerYsa Power Platform Enthusiast [LinkedIn] | [Youtube]

    I love to share my knowledge and learn from others. If you find my posts helpful, please give them a thumbs up 👍 or mark them as a solution ✔️. You can also check out my [@PowerYSA] for some cool solutions and insights. Feel free to connect with me on any of the platforms above. Cheers! 🍻

  • Verified answer
    timl Profile Picture
    36,634 Super User 2026 Season 1 on at

    Hi @Runner55552 

    If you're looking for some formula to apply this transformation to a collection, let's say you have a collection that looks like this:

    ClearCollect(colData,
     {Code: "WW031-231"}, {Code: "DT031-222"}
    )

    You can call the AddColumns function to apply this transformation to the collection.

    AddColumns(colData, 
     "NewCode", 
     With({splitStr:Split(Code, "-")}, 
     Left(Code, 2) & "-" & 
     Mid( First(splitStr).Value,3, Len(First(splitStr).Value)-2) & "-" &
     Last(splitStr).Value 
     )
    )

     

    timl_0-1708647193870.png

     

  • 55552 Profile Picture
    674 on at

    Thanks. This looks like it would work. Accepted the first suggestion above from @SpongYe as the solution, partly because it came in first, but both solutions appear to work.

  • timl Profile Picture
    36,634 Super User 2026 Season 1 on at

    Thanks @Runner55552 - I'm glad that works for you. Please note that it's possible to select multiple posts as solutions in situations like this.

  • 55552 Profile Picture
    674 on at

    Thanks! Just accepted yours also. I did not know you could accept more than one solution. Also, I just tried your solution in my app and it worked well. Since some of my codes have a different format (132-2344 or 132-234), without letters at the front, I needed to wrap an If statement around the With code to check the total length of the string. If >= 9 characters, implement the With statement, else keep the original text.

    I have also noticed that I cannot use AddColumns on an existing collection. It appears to add columns to a collection, I need to create a new collection. Is that correct?

    Runner55552_0-1709217724443.png

     

  • timl Profile Picture
    36,634 Super User 2026 Season 1 on at

    Hi @Runner55552 

    Thanks - that's correct - AddColumns doesn't add columns to an existing collection - it's a function that returns a table with the additional columns you specify. Therefore, you would need to Collect to a new collection, or you can do as I did in the screenshot and set the Items property of a gallery, datatable or control directly to the call to AddColumns.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 248 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 209 Super User 2026 Season 1

#3
VASANTH KUMAR BALMADI Profile Picture

VASANTH KUMAR BALMADI 195

Last 30 days Overall leaderboard