Letraindusoir Posted October 8, 2019 Share Posted October 8, 2019 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=D:\MESS\桌面\Form1_1.kxf $Form1_1 = GUICreate("Form1",720, 406, 192, 114) GUISetFont(12) GUICtrlCreateLabel("String1", 14, 8, 60, 17) $idEdt1 = GUICtrlCreateEdit("", 80, 8, 630, 49, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "Boats sail on the rivers,And ships sail on the seas") GUICtrlCreateLabel("String2", 14, 63, 60, 17) $idEdt2 = GUICtrlCreateEdit("", 80, 63, 630, 49, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "But clouds that sail across the sky,Are prettier far than these.") GUICtrlCreateLabel("hyphen", 14, 135, 60, 17) $idEdt3 = GUICtrlCreateEdit("@CRLF", 80, 135, 201, 49, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetFont($idEdt3,18) $idJoin = GUICtrlCreateButton("JOIN", 317, 135, 129, 49) GUICtrlCreateLabel("Result", 14, 205,60, 17) $idEdt4 = GUICtrlCreateEdit("", 80, 205, 630, 185, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL,$WS_HSCROLL)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $idJoin local $String1=GUICtrlRead($idEdt1) local $String2=GUICtrlRead($idEdt2) local $sHyphen=GUICtrlRead($idEdt3) local $sResult=$String1 & $sHyphen & $String2 GUICtrlSetData($idEdt4,$sResult) EndSwitch WEnd If want to fill in the following string in the hyphen-edit-box: "@CRLF" "\r\n" ";" $Var="/" "Var" and display the results correctly in the Result-edit-box, how do convert it? Thanks in advance! Edited October 8, 2019 by Letraindusoir Link to comment Share on other sites More sharing options...
Developers Jos Posted October 8, 2019 Developers Share Posted October 8, 2019 Moved to the appropriate forum. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
mikell Posted October 8, 2019 Share Posted October 8, 2019 GuiCtrlRead returns a string, and in this case you get "@crlf" as a string litteral You should build your own conversion table (using a 2D array could be a good idea) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Form1",720, 406, 192, 114) GUISetFont(12) GUICtrlCreateLabel("String1", 14, 8, 60, 17) $idEdt1 = GUICtrlCreateEdit("", 80, 8, 630, 49, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "Boats sail on the rivers,And ships sail on the seas") GUICtrlCreateLabel("String2", 14, 63, 60, 17) $idEdt2 = GUICtrlCreateEdit("", 80, 63, 630, 49, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetData(-1, "But clouds that sail across the sky,Are prettier far than these.") GUICtrlCreateLabel("hyphen", 14, 135, 60, 17) $idEdt3 = GUICtrlCreateEdit("newline", 80, 135, 201, 49, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetFont($idEdt3,18) $idJoin = GUICtrlCreateButton("JOIN", 317, 135, 129, 49) GUICtrlCreateLabel("Result", 14, 205,60, 17) $idEdt4 = GUICtrlCreateEdit("", 80, 205, 630, 185, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL,$WS_HSCROLL)) GUISetState(@SW_SHOW) local $sHyphen While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $idJoin local $String1=GUICtrlRead($idEdt1) local $String2=GUICtrlRead($idEdt2) If GUICtrlRead($idEdt3) = "newline" Then $sHyphen=@crlf local $sResult=$String1 & $sHyphen & $String2 GUICtrlSetData($idEdt4,$sResult) EndSwitch WEnd Link to comment Share on other sites More sharing options...
Letraindusoir Posted October 8, 2019 Author Share Posted October 8, 2019 48 minutes ago, mikell said: GuiCtrlRead returns a string, and in this case you get "@crlf" as a string litteral You should build your own conversion table (using a 2D array could be a good idea) Thank you, Mikell! I ask this problem not just to type a specific string into a variable, but to get a general approach. To put it simply, how to convert a variable-name-string into the variable self , especially when GUI_Edit_Box in the software interface allows users to enter uncertain strings, can automatically convert them correctly when they are found to be macro-variable or regular-metacharacters, or declared-variable-name Link to comment Share on other sites More sharing options...
Letraindusoir Posted October 8, 2019 Author Share Posted October 8, 2019 As shown in the above two figures, if want to replace more than two spaces with newline characters, if the string read directly by the input box is not converted, may not be able to replace it correctly. Link to comment Share on other sites More sharing options...
seadoggie01 Posted October 8, 2019 Share Posted October 8, 2019 That's what Mikell is suggesting You'll want to build a 2D array with a name in the first column and a replacement value in the second. ; Your list of replacements Local $aReplacements[10][2] = [ _ ["@CRLF", @CRLF], _ ["@TAB", @TAB], _ ["@CR", @CR] _ ] ; For each replacement For $i=0 To UBound($aReplacements) - 1 ; Make the replacement $something = StringReplace($something, $aReplacements[$i][0], $aReplacements[$i][1]) Next As for already declared variables, that seems strange... do you mean that you would allow the user to store variables or that they could use variables that you program into the program? For the former, you could build another replacement array, where it contains the variable name and the value. For the latter, you'll want to look at Eval. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
jchd Posted October 8, 2019 Share Posted October 8, 2019 7 hours ago, Letraindusoir said: how to convert a variable-name-string into the variable self Like this? Local $myVar = 3.1415926 Local $s = "my var name = $myvar$" Opt("ExpandVarStrings", 1) ConsoleWrite($s & @LF) ConsoleWrite("CR then LF is @CRLF@" & "CR then LF inserted!" & @LF) Letraindusoir 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Letraindusoir Posted October 11, 2019 Author Share Posted October 11, 2019 On 10/9/2019 at 4:18 AM, jchd said: Like this? Local $myVar = 3.1415926 Local $s = "my var name = $myvar$" Opt("ExpandVarStrings", 1) ConsoleWrite($s & @LF) ConsoleWrite("CR then LF is @CRLF@" & "CR then LF inserted!" & @LF) Thank you very much! Your answer directly contributed to the solution of the following problems! Link to comment Share on other sites More sharing options...
Letraindusoir Posted October 11, 2019 Author Share Posted October 11, 2019 Local $myVar = 3.1415926 p("$myVar$") func P($Var) ConsoleWrite($Var & "=[") Opt("ExpandVarStrings", 1) ConsoleWrite($Var & "]" & @CRLF) Opt("ExpandVarStrings", 0) endfunc Link to comment Share on other sites More sharing options...
Letraindusoir Posted October 11, 2019 Author Share Posted October 11, 2019 Local $sStr="Boats sail on the rivers,And ships sail on the seas,But clouds that sail across the sky,Are prettier far than these." local $sNew=StringRegexReplace($sStr,",","\r\n") consolewrite($sNew) ask a regular question, as shown above, how to replace all commas in a string with whitespace represented by regular-metacharacters (for example,\ r\ n)? It's not working above. Link to comment Share on other sites More sharing options...
jchd Posted October 11, 2019 Share Posted October 11, 2019 In the replacement part of StringRegexReplace(), only $1, $2, $3 ... (or \1, \2, \3 ...) are recognized. \r\n is a C thing while AutoIt conveniently offers @CRLF. But here the regexp isn't even necessary: Local $sStr = "Boats sail on the rivers,And ships sail on the seas,But clouds that sail across the sky,Are prettier far than these." local $sNew = StringReplace($sStr, ",", @CRLF) consolewrite($sNew) 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 hereRegExp tutorial: enough to get startedPCRE 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 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