Jump to content

Split String and Wrap Each Word in Quotations


Go to solution Solved by Nine,

Recommended Posts

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
Posted (edited)

Christ.. I'm embarrassed 😟 I was expecting a lengthy, complicated expression - didn't think it would be so simple. Thanks guys!

Edited by Luke94
Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...