Sign in to follow this  
Followers 0
guinness

[Solved] StringRegExpReplace - INI Key & Value in a String

11 posts in this topic

#1 ·  Posted (edited)

The below will change the Value of the Key.

$sString = "ABCExample0=Return0|Example0=Return1|EXAMPLE2=Return2|Example3=Return3|Example4=Return4|"
$sStringEx = "ABCExample0=ABCNewReturn0|Example0=NewReturn1|Example2=NewReturn2|Example3=NewReturn3|Example4=NewReturn4|"

$sString = "|" & $sString

Global $aActualKeys[5] = ["ABCExample0", "Example0", "Example2", "Example3", "Example4"]
Global $aNewReturns[5] = ["ABCNewReturn0", "NewReturn1", "NewReturn2", "NewReturn3", "NewReturn4"]

For $i = 0 To 4

    $sFind = "\|" & $aActualKeys[$i] & "=.+\|"
    $sWrite = "\|" & $aActualKeys[$i] & "=" & $aNewReturns[$i] & "|"
    $sString = StringRegExpReplace($sString, "(?i)(?U)" & $sFind, $sWrite)

Next

$sString = StringTrimLeft($sString, 1)

ConsoleWrite("Should Be Result => " & $sStringEx & @CRLF)
ConsoleWrite("Actual Result    => " & $sString & @CRLF)
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites



guinness,

4 points:

- 1: Based on your example, I assume you want to replace "Return", not "Example" - so I would suggest that:

$sFind = "Example"

should read:

$sFind = "Return"

- 2: You need a variable to hold the returned string! :P

- 3: WTF is loop doing? ;)

- 4: Why use StringRegExpReplace anyway? You only need the much simpler StringReplace: ;)

$sString = "Example0=Return0|Example1=Return1|Example2=Return2|Example3=Return3|Example4=Return4|"
$sStringEx = "Example0=NewReturn0|Example1=NewReturn1|Example2=NewReturn2|Example3=NewReturn3|Example4=NewReturn4|"

$sFind = "Return"
$sWrite = "NewReturn"
$sNewString = StringReplace($sString, $sFind, $sWrite) ; You need the new variable

ConsoleWrite("Should Be Result => " & $sStringEx & @CRLF)
ConsoleWrite("Actual Result    => " & $sNewString & @CRLF)

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

- 3: WTF is loop doing? ;)

Best oneliner on the Forums today.... :)

For some odd reason I think he is using the for statement to parse the five string value keys in each line, right? Though I was scratching my head at first trying to figure out why he did it like this....

Edited by targeter

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

- 1:, -2:, -3:

WTF is the loop doing? ;)

The example was taken from here
http://www.autoitscript.com/forum/index.php?showtopic=118824&view=findpost&p=826416
The loop is there to replace key values e.g. Example0=, Example1=

It was created by PSaltyDS.

- 4: Why use StringRegExpReplace anyway? You only need the much simpler StringReplace: :)

Because this is an INI File which is created into a string. The KeyValues are all unique but the Value might be the same in certain KeysValues e.g. "Example0=Return|Example1=Return1|Example2=Return|Example3=NewReturn3|Example4=NewReturn4|" so this is why I didn't opt for StringReplace.

Example:

Global $sString = "Example0=Return0|Example1=Return1|Example2=Return2|Example3=Return3|Example4=Return4|"
_Example("Example0","NewValue") ; Replace the Key Example0= with a Value of NewValue

Func _Example($sValue, $sWrite = "Example")
    StringRegExpReplace($sString, "(?U)(?:\A|\|)(?:" & $sValue & "=)(.+)(?:$|\|)", $sWrite & "|") ; PSaltyDS
    Return 1
EndFunc   ;==>_Example
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

guinness,

What I posted did exactly what you asked for with your $sString and $sStringEx samples. If you do not give all the information, you cannot expect to get reasonable answers! :)

Do I understand that you want to replace specific values with specific new_values? If so then this might be a way to do it: ;)

$sString = "Example0=Return0|Example1=Return1|Example2=Return2|Example3=Return3|Example4=Return4|"
$sStringEx = "Example0=NewReturn0|Example1=NewReturn1|Example2=NewReturn2|Example3=NewReturn3|Example4=NewReturn4|"

Global $aNewReturns[5] = ["NewReturn0", "NewReturn1", "NewReturn2", "NewReturn3", "NewReturn4"]

For $i = 0 To 4

    $sFind = "Example" & $i & "=.+\|"
    $sWrite = "Example" & $i & "=" & $aNewReturns[$i] & "|"

    $sString = StringRegExpReplace($sString, "(?U)" & $sFind, $sWrite)

Next

ConsoleWrite("Should Be Result => " & $sStringEx & @CRLF)
ConsoleWrite("Actual Result    => " & $sString & @CRLF)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Excellent! That is what I was looking for. I had a little play with the code and changed a few sections marked with <<<<<<. A problem I noticed is $sFind isn't case sensitive and I think "?:\A" might need to be included, but still a novice at RegExp. I tried this $sString = StringRegExpReplace($sString, "(?U)(?:\A)(?:" & $sFind, $sWrite) but it didn't seem to work correctly.

If you run following code below "ABCExample0" is changed even though it shouldn't as it doesn't match "Example0". Thanks

$sString = "ABCExample0=Return0|Example1=Return1|Example2=Return2|Example3=Return3|Example4=Return4|" ; <<<<<< ABCExample0 changes.
Global $aNewReturns[5] = ["NewReturn0", "NewReturn1", "NewReturn2", "NewReturn3", "NewReturn4"]

For $i = 0 To 4
    $sFind = "Example" & $i & "=)(.+)(?:$|\|)" ; <<<<<< Changed from "=.+\|", This means if there is a missing "|" at the end of the string it will still change the value.
    $sWrite = "Example" & $i & "=" & $aNewReturns[$i] & "|"

    $sString = StringRegExpReplace($sString, "(?U)(?:" & $sFind, $sWrite) ; <<<<<< Changed from "(?U)(?:"

Next
ConsoleWrite("Result    => " & $sString & @CRLF)

See the example below as well ABCExample0 & Example0 are both changed.

Global $sString = "ABCExample0=Return0|Example0=Return1|Example2=Return2|Example3=Return3|Example4=Return4|"
_Example("Example0","NewValue") ; Replace the Key Example0= with a Value of NewValue

Func _Example($sValue, $sWrite = "Example")
    $sString = StringRegExpReplace($sString, "(?U)(?:" & $sValue & "=)(.+)(?:$|\|)", $sValue & "=" & $sWrite & "|")
    Return 1
EndFunc   ;==>_Example

ConsoleWrite($sString & @CRLF)
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This seems to work, but its a little cack-handed way of doing it. I add (?:\A|\|) and ["|" &] at the beginning of the Replace section.

$sString = "Example0=Return0|Example1=Return1|Example2=Return2|Example3=Return3|Example4=Return4|"
Global $aNewReturns[5] = ["NewReturn0", "NewReturn1", "NewReturn2", "NewReturn3", "NewReturn4"]

For $i = 0 To 4
    $sFind = "Example" & $i & "=)(.+)(?:$|\|)" ; <<<<<< Changed from "=.+\|", This means if there is a missing "|" at the end of the string it will still change the value.
    $sWrite = "|" & "Example" & $i & "=" & $aNewReturns[$i] & "|"

    $sString = StringRegExpReplace($sString, "(?U)(?:\A|\|)(?:" & $sFind, $sWrite) ; <<<<<< Changed from ""(?U)(?:\A|\|)(?:" exact match

Next
ConsoleWrite("Result    => " & $sString & @CRLF)

Global $sString = "ABCExample0=Return0|Example0=Return1|Example2=Return2|Example3=Return3|Example4=Return4|"
_Example("Example0","NewValue") ; Replace the Key Example0= with a Value of NewValue
_Example("ABCExample0","NewValueABC") ; Replace the Key ABCExample0= with a Value of NewValueABC, but it adds "|" at the start of the string, which is expected, but not ideal.

Func _Example($sValue, $sWrite = "Example")
    $sString = StringRegExpReplace($sString, "(?U)(?:\A|\|)(?:" & $sValue & "=)(.+)(?:$|\|)", "|" & $sValue & "=" & $sWrite & "|")
    ConsoleWrite($sString & @CRLF)
    Return 1
EndFunc   ;==>_Example
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

guinness,

I hope you will not mind me saying this, but the one thing that really gets my goat on this forum is when people keep changing the goalposts as the thread develops! ;)

Anyway, if you make one small change (add a "|" at the beginning of your strings) this should work - for the latest iteration at least ;) :

$sString = "|ABCExample0=Return0|Example0=Return1|EXAMPLE2=Return2|Example3=Return3|Example4=Return4|"
$sStringEx = "|ABCExample0=ABCNewReturn0|Example0=NewReturn1|Example2=NewReturn2|Example3=NewReturn3|Example4=NewReturn4|"

Global $aActualKeys[5] = ["ABCExample0", "Example0", "Example2", "Example3", "Example4"]
Global $aNewReturns[5] = ["ABCNewReturn0", "NewReturn1", "NewReturn2", "NewReturn3", "NewReturn4"]

For $i = 0 To 4

    $sFind = "[\A\|]" & $aActualKeys[$i] & "=.+\|"
    $sWrite = "\|" & $aActualKeys[$i] & "=" & $aNewReturns[$i] & "|"
    ConsoleWrite($sFind & @CRLF)
    ConsoleWrite($sWrite & @CRLF)

    $sString = StringRegExpReplace($sString, "(?i)(?U)" & $sFind, $sWrite)
    $Ext = @extended
    ConsoleWrite($Ext & @CRLF)
    If $Ext > 2 Then Exit


Next

ConsoleWrite("Should Be Result => " & $sStringEx & @CRLF)
ConsoleWrite("Actual Result    => " & $sString & @CRLF)

I am afraid it is too late for me to work on an SRE for the string which does not begin with a "|" - perhaps tomorrow. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Sorry, it wasn't my intention. It was complete by about post 6. I was simply asking whether I was understanding the StringRegExp values to include a case sensitive check and the "|" at the start of the string is a little cosmetic thing. I am sure StringTrim will come in handy! I don't think I have been that bad, I did give examples and tried myself. ;)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

guinness,

I don't think I have been that bad

Apologies, I was feeling crochety last night - comes with age, you know! :)

This is my final effort:

$sString = "ABCExample0=Return0|Example0=Return1|EXAMPLE2=Return2|Example3=Return3|Example4=Return4|"
$sStringEx = "ABCExample0=ABCNewReturn0|Example0=NewReturn1|Example2=NewReturn2|Example3=NewReturn3|Example4=NewReturn4|"

$sString = "|" & $sString

Global $aActualKeys[5] = ["ABCExample0", "Example0", "Example2", "Example3", "Example4"]
Global $aNewReturns[5] = ["ABCNewReturn0", "NewReturn1", "NewReturn2", "NewReturn3", "NewReturn4"]

For $i = 0 To 4

    $sFind = "\|" & $aActualKeys[$i] & "=.+\|"
    $sWrite = "\|" & $aActualKeys[$i] & "=" & $aNewReturns[$i] & "|"
    $sString = StringRegExpReplace($sString, "(?i)(?U)" & $sFind, $sWrite)

Next

$sString = StringTrimLeft($sString, 1)

ConsoleWrite("Should Be Result => " & $sStringEx & @CRLF)
ConsoleWrite("Actual Result    => " & $sString & @CRLF)

I am annoyed with myself for not being able to deal with the "|" at the beginning within the SRE, but as I often say, they are probably the hardest things I have ever tried to learn in computing.

I hope that suffices for your script. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks ever so much. If you find SRE's difficult imagine how us minions find them ;)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


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
Sign in to follow this  
Followers 0