Luke94 32 Posted June 6 Share Posted June 6 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 post Share on other sites
Solution Nine 1,521 Posted June 6 Solution Share Posted June 6 This ? Local $sText = "Item 1, Item@2, Item_3, Item/4, Item-5" Local $sFinal = '"' & StringRegExpReplace($sText, '(, )', '", "') & '"' ConsoleWrite($sFinal & @CRLF) Luke94 1 Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in 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 GIF Animation (cached) Screen Scraping Link to post Share on other sites
Subz 806 Posted June 6 Share Posted June 6 Or Local $sString = 'Item 1, Item@2, Item_3, Item/4, Item-5' $sString = '"' & StringReplace($sString, ", ", '", "') & '"' Luke94 1 Link to post Share on other sites
Luke94 32 Posted June 6 Author Share Posted June 6 (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 by Luke94 Link to post Share on other sites
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