Luke94 Posted June 6, 2022 Share Posted June 6, 2022 Hi, I have the following string: Quote Item 1, Item@2, Item_3, Item/4, Item-5 I'm wanting to wrap each word in quotations whilst keeping them comma delimited. The output should look like: Quote "Item 1", "Item@2", "Item_3", "Item/4", "Item-5" I'm able to achieve this with the following code: #include <Array.au3> #include <String.au3> Local $sString = 'Item 1, Item@2, Item_3, Item/4, Item-5' Local $aItems = StringSplit($sString, ', ', ($STR_ENTIRESPLIT + $STR_NOCOUNT)) Local $sOutput For $i = 0 To (UBound($aItems) - 1) Step 1 $sOutput &= StringFormat('"%s"', $aItems[$i]) If $i < (UBound($aItems) - 1) Then $sOutput &= ', ' Next ConsoleWrite($sOutput) But I'm wondering if there's a StringRegExpReplace one liner that can do this? All searches seem to be bringing up stripping the quotations or replacing words between them. RegEx is one of my weaknesses - I can't seem to get my head around it 😢 Link to comment Share on other sites More sharing options...
Solution Nine Posted June 6, 2022 Solution Share Posted June 6, 2022 This ? Local $sText = "Item 1, Item@2, Item_3, Item/4, Item-5" Local $sFinal = '"' & StringRegExpReplace($sText, '(, )', '", "') & '"' ConsoleWrite($sFinal & @CRLF) Luke94 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted June 6, 2022 Share Posted June 6, 2022 Or Local $sString = 'Item 1, Item@2, Item_3, Item/4, Item-5' $sString = '"' & StringReplace($sString, ", ", '", "') & '"' Luke94 1 Link to comment Share on other sites More sharing options...
Luke94 Posted June 6, 2022 Author Share Posted June 6, 2022 (edited) Christ.. I'm embarrassed 😟 I was expecting a lengthy, complicated expression - didn't think it would be so simple. Thanks guys! Edited June 6, 2022 by Luke94 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now