Jump to content

add quotations to a multi-line string


gcue
 Share

Recommended Posts

hello world =)

I am having trouble adding quotes around the values of each line containing =.  For example, I would like lines 3 and 4 to read

Quote

$reg_changes[0][0] = "NON_ADMIN"

;adding quotes around NON_ADMIN

$reg_changes[0][1] = "Windows - Default Restart Button"

;adding quotes around "Windows - Default Restart Button" 

$string = 'Local $reg_changes[4][8]' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[0][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[0][1] = Windows - Default Restart Button' & @CRLF
$string &= '$reg_changes[0][2] = HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' & @CRLF
$string &= '$reg_changes[0][3] = Start_PowerButtonAction' & @CRLF
$string &= '$reg_changes[0][4] = REG_DWORD' & @CRLF
$string &= '$reg_changes[0][5] = 4' & @CRLF
$string &= '$reg_changes[0][6] = Requires Restart To Take Effect' & @CRLF
$string &= '$reg_changes[0][7] = ' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[1][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[1][1] = SnagIT Editor - Run in Background' & @CRLF
$string &= '$reg_changes[1][2] = HKEY_CURRENT_USER\Software\TechSmith\SnagIt\11' & @CRLF
$string &= '$reg_changes[1][3] = AlwaysKeepEditorOpen' & @CRLF
$string &= '$reg_changes[1][4] = REG_DWORD' & @CRLF
$string &= '$reg_changes[1][5] = 1' & @CRLF
$string &= '$reg_changes[1][6] = ' & @CRLF
$string &= '$reg_changes[1][7] = snagit.exe|snagiteditor.exe' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[2][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[2][1] = Windows - Disable Auto Window Maximizing' & @CRLF
$string &= '$reg_changes[2][2] = HKEY_CURRENT_USER\Control Panel\Desktop' & @CRLF
$string &= '$reg_changes[2][3] = WindowArrangementActive' & @CRLF
$string &= '$reg_changes[2][4] = REG_SZ' & @CRLF
$string &= '$reg_changes[2][5] = 0' & @CRLF
$string &= '$reg_changes[2][6] = Requires Restart To Take Effect' & @CRLF
$string &= '$reg_changes[2][7] = ' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[3][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[3][1] = Mouse Cursor - Display Pointer Trails' & @CRLF
$string &= '$reg_changes[3][2] = HKEY_CURRENT_USER\Control Panel\Cursors' & @CRLF
$string &= '$reg_changes[3][3] = Scheme Source' & @CRLF
$string &= '$reg_changes[3][4] = REG_DWORD' & @CRLF
$string &= '$reg_changes[3][5] = 0' & @CRLF
$string &= '$reg_changes[3][6] = Requires Restart To Take Effect' & @CRLF
$string &= '$reg_changes[3][7] = ' & @CRLF

$string2 = StringRegExpReplace($string, "=[\S]*", '="[\S]*', "$1")

ConsoleWrite($string2 & @crlf)

thank you in advance!

Edited by gcue
Link to comment
Share on other sites

$string2 = StringRegExpReplace($string, "((?<==\s).+)", '"$1"')

should do.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

In this example the first three stringRegExpReplace functions puts everything following "=" and a space (like text, digits or nothing) in between double quotes.

The last example stringRegExpReplace function does not put following digits in double quotes.

$string = 'Local $reg_changes[4][8]' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[0][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[0][1] = Windows - Default Restart Button' & @CRLF
$string &= '$reg_changes[0][2] = HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' & @CRLF
$string &= '$reg_changes[0][3] = Start_PowerButtonAction' & @CRLF
$string &= '$reg_changes[0][4] = REG_DWORD' & @CRLF
$string &= '$reg_changes[0][5] = 4' & @CRLF
$string &= '$reg_changes[0][6] = Requires Restart To Take Effect' & @CRLF
$string &= '$reg_changes[0][7] = ' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[1][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[1][1] = SnagIT Editor - Run in Background' & @CRLF
$string &= '$reg_changes[1][2] = HKEY_CURRENT_USER\Software\TechSmith\SnagIt\11' & @CRLF
$string &= '$reg_changes[1][3] = AlwaysKeepEditorOpen' & @CRLF
$string &= '$reg_changes[1][4] = REG_DWORD' & @CRLF
$string &= '$reg_changes[1][5] = 1' & @CRLF
$string &= '$reg_changes[1][6] = ' & @CRLF
$string &= '$reg_changes[1][7] = snagit.exe|snagiteditor.exe' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[2][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[2][1] = Windows - Disable Auto Window Maximizing' & @CRLF
$string &= '$reg_changes[2][2] = HKEY_CURRENT_USER\Control Panel\Desktop' & @CRLF
$string &= '$reg_changes[2][3] = WindowArrangementActive' & @CRLF
$string &= '$reg_changes[2][4] = REG_SZ' & @CRLF
$string &= '$reg_changes[2][5] = 0' & @CRLF
$string &= '$reg_changes[2][6] = Requires Restart To Take Effect' & @CRLF
$string &= '$reg_changes[2][7] = ' & @CRLF
$string &= '' & @CRLF
$string &= '$reg_changes[3][0] = NON_ADMIN' & @CRLF
$string &= '$reg_changes[3][1] = Mouse Cursor - Display Pointer Trails' & @CRLF
$string &= '$reg_changes[3][2] = HKEY_CURRENT_USER\Control Panel\Cursors' & @CRLF
$string &= '$reg_changes[3][3] = Scheme Source' & @CRLF
$string &= '$reg_changes[3][4] = REG_DWORD' & @CRLF
$string &= '$reg_changes[3][5] = 0' & @CRLF
$string &= '$reg_changes[3][6] = Requires Restart To Take Effect' & @CRLF
$string &= '$reg_changes[3][7] = ' & @CRLF

MsgBox(0, "StringRegExpReplace($string, ""(?m)\h+([^=\v]*)$"", ' ""$1""')", StringRegExpReplace($string, "(?m)\h+([^=\v]*)$", ' "$1"'))
MsgBox(0, "StringRegExpReplace($string, ""=\h*(.*)"",  '= ""$1""')",        StringRegExpReplace($string, "=\h*(.*)", '= "$1"'))
MsgBox(0, "StringRegExpReplace($string, ""(?<=\=\h)(.*)"",  '""$1""')",     StringRegExpReplace($string, "(?<=\=\h)(.*)", '"$1"'))


$string2 = '"' & StringRegExpReplace($string, "(?<=\=\h)(.*)", '" & _Test("$1") & "') & '"'
;MsgBox(0,"",$string2)
MsgBox(0, "Function _Test() used", Execute($string2))


Func _Test($Text)
    If $Text <> "" And StringRegExp($Text, "\D+") = 0 Then
        Return $Text
    Else
        Return '"' & $Text & '"'
    EndIf
EndFunc   ;==>_Test

 

 

 

Edited by Malkey
(?<=\=\h) can also be (?<==\h)
Link to comment
Share on other sites

thank you for your help!

jchd, the pattern you provided for some reason adds a vertical linefeed before the second quote

Malkey, same with your second pattern

cant see where its being added in either case

thank you again!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...