Mavnus04 Posted May 20, 2020 Share Posted May 20, 2020 (edited) Hi, I am trying to get user input saved that could contain single and/or double quotes, then save that into another .au3 file to be used later as variables. Code I am having a problem with: Func WriteWindowsNames($arr) Local $VarArr[9] $VarArr[3] = "Global $UnityName = '" & $arr[3] & "'" ;Save results to a file WriteFileFromArray(@ScriptDir & '\WindowsNames.au3', $VarArr) EndFunc WriteFileFromArray is just my wrapper function of _FileWriteFromArray($path, $array) with some extra checks. Works fine if I have $arr[3] = 'Thats Bananas' and that prints out to file as: Global $UnityName = 'Thats Bananas' But if $arr[3] = 'That's Bananas' with the extra single quote, and that prints out to file as: Global $UnityName = 'That's Bananas' When that is read by AutoIt, it sometimes breaks or doesn't work. How can I adjust my $VarArr[3] line to accept or check for single/double quotes from the user? Can it be done without an if statement, because then I will need 10 times for the others similar to it? Edited May 20, 2020 by Mavnus04 Added more code Link to comment Share on other sites More sharing options...
argumentum Posted May 20, 2020 Share Posted May 20, 2020 ..would you post running code that shows the problem @Mavnus04 ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
argumentum Posted May 20, 2020 Share Posted May 20, 2020 Global $UnityName = 'That''s Bananas' ConsoleWrite($UnityName & @CRLF) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Mavnus04 Posted May 20, 2020 Author Share Posted May 20, 2020 (edited) Func WriteWindowsNames($arr) Local $VarArr[9] $VarArr[3] = "Global $UnityName = '" & $arr[3] & "'" ;Save results to a file WriteFileFromArray(@ScriptDir & '\WindowsNames.au3', $VarArr) EndFunc WriteFileFromArray is just my wrapper function of _FileWriteFromArray($path, $array) with some extra checks. I removed the other variables from the array to keep it short. Edited May 20, 2020 by Mavnus04 Link to comment Share on other sites More sharing options...
argumentum Posted May 20, 2020 Share Posted May 20, 2020 I home this helps. I'm sure that your code concept is impractical. Global $UnityName = 'That''s Bananas' ConsoleWrite($UnityName & @CRLF) WriteWindowsNames($UnityName) Func WriteWindowsNames($arr) Local $VarArr[9] $VarArr[3] = 'Global $UnityName = "' & $arr & '"' ;Save results to a file ;~ WriteFileFromArray(@ScriptDir & '\WindowsNames.au3', $VarArr) MsgBox(0,"", $VarArr[3], 30) EndFunc Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Mavnus04 Posted May 20, 2020 Author Share Posted May 20, 2020 1 minute ago, argumentum said: I home this helps. I'm sure that your code concept is impractical. Global $UnityName = 'That''s Bananas' ConsoleWrite($UnityName & @CRLF) WriteWindowsNames($UnityName) Func WriteWindowsNames($arr) Local $VarArr[9] $VarArr[3] = 'Global $UnityName = "' & $arr & '"' ;Save results to a file ;~ WriteFileFromArray(@ScriptDir & '\WindowsNames.au3', $VarArr) MsgBox(0,"", $VarArr[3], 30) EndFunc This only helps if the user input uses single quotes. I need to cover if the user inputs single and/or double quotes. That's Bananas" "That's Bananas" "Thats Bananas" Link to comment Share on other sites More sharing options...
argumentum Posted May 20, 2020 Share Posted May 20, 2020 #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() #Region ### START Koda GUI section ### Form= Local $Form1 = GUICreate("Form1", 335, 84) Local $Input1 = GUICtrlCreateInput("Input1 ' """, 8, 8, 121, 21) Local $Button1 = GUICtrlCreateButton("Button1", 136, 8, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Exit Case $Button1 MsgBox(0,"",GUICtrlRead($Input1) & @CR & StringToBinary(GUICtrlRead($Input1)), 60, $Form1) EndSwitch WEnd EndFunc Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Mavnus04 Posted May 20, 2020 Author Share Posted May 20, 2020 #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> Example() Func Example() #Region ### START Koda GUI section ### Form= Local $Form1 = GUICreate("Form1", 335, 84) Local $Input1 = GUICtrlCreateInput("Input1 ' """, 8, 8, 121, 21) Local $Button1 = GUICtrlCreateButton("Button1", 136, 8, 75, 25) local $array[2] GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Exit Case $Button1 MsgBox(0,"",GUICtrlRead($Input1) & @CR & StringToBinary(GUICtrlRead($Input1)), 60, $Form1) $array[0] = "Global $UnityName = '" & GUICtrlRead($Input1) & "'" $array[1] = StringToBinary(GUICtrlRead($Input1)) _FileWriteFromArray("C:\Users\Matthew.Mumm\Desktop\Output.txt", $array) EndSwitch WEnd EndFunc gives the same issue. File output: Global $CefName = 'Input1 ' "' 0x496E7075743120272022 Link to comment Share on other sites More sharing options...
argumentum Posted May 20, 2020 Share Posted May 20, 2020 (edited) ..what I meant by: 31 minutes ago, argumentum said: I'm sure that your code concept is impractical ,is that you are creating a script with a script. I'm sure that whatever you want to accomplish ( and have not shared ), can be done in a more "elegant" way Edited May 20, 2020 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
argumentum Posted May 20, 2020 Share Posted May 20, 2020 #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() #Region ### START Koda GUI section ### Form= Local $Form1 = GUICreate("Form1", 335, 84) Local $Input1 = GUICtrlCreateInput("Input1 ' """, 8, 8, 121, 21) Local $Button1 = GUICtrlCreateButton("Button1", 136, 8, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Exit Case $Button1 ConsoleWrite('Global $var = "' & StringReplace(GUICtrlRead($Input1), '"', '""') & '"' & @CRLF) MsgBox(0, "", GUICtrlRead($Input1) & @CR & _ 'Global $var = "' & StringReplace(GUICtrlRead($Input1), '"', '""') & '"', 60, $Form1) EndSwitch WEnd EndFunc ;==>Example Mavnus04 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Mavnus04 Posted May 20, 2020 Author Share Posted May 20, 2020 Ahh Ha! 'Global $var = "' & StringReplace(GUICtrlRead($Input1), '"', '""') & '"' Changing the surrounding quotes to single quotes, then replacing one double quote with 2 double quotes did the trick. Thank you. Link to comment Share on other sites More sharing options...
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