Jump to content

Split String and Wrap Each Word in Quotations

Go to solution Solved by Nine,

Recommended Posts


I have the following string:


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:


"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 &= ', '


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

  • Solution

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...