prodesigner Posted August 3, 2019 Share Posted August 3, 2019 I would appreciate if someone show how to convert the result of this code to string and to show the result in MsgBox. Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] Local $aIgnore[3] = ["b", "d", "g"] For $j = 0 To UBound($aCheck) - 1 ; Get the next item in the array to check $sItem = $aCheck[$j] ; Set a flag $fValid = True ; Now loop through the exceptions For $i = 0 To UBound($aIgnore) - 1 ; If it matches clear the flag If $sItem == $aIgnore[$i] Then $fValid = False EndIf Next ; If the flag is set it is a valid item If $fValid Then ConsoleWrite($aCheck[$j] & @CRLF) Next I tried this with no luck: $Result = _ArrayToString($aCheck[$j], ", ", 1) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 3, 2019 Moderators Share Posted August 3, 2019 (edited) Technically, just putting a MsgBox in place of the ConsoleWrite works just fine; you get one MsgBox per letter in your for loop, just like consolewrite is outputting one letter per cycle through the loop: I am guessing, though, what you mean is that you're after one MsgBox at the end with the entire string, something like this: #include <MsgBoxConstants.au3> Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] Local $aIgnore[3] = ["b", "d", "g"] $sString = "" For $j = 0 To UBound($aCheck) - 1 ; Get the next item in the array to check $sItem = $aCheck[$j] ; Set a flag $fValid = True ; Now loop through the exceptions For $i = 0 To UBound($aIgnore) - 1 ; If it matches clear the flag If $sItem == $aIgnore[$i] Then $fValid = False EndIf Next ; If the flag is set it is a valid item If $fValid Then $sString &= $aCheck[$j] & "," Next MsgBox($MB_OK, "MyString", StringTrimRight($sString, 1)) Edited August 3, 2019 by JLogan3o13 prodesigner 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
prodesigner Posted August 3, 2019 Author Share Posted August 3, 2019 Awesome, thanks. Is it possible to replace string in this line If $fValid Then $sString &= $aCheck[$j] & "," With an array _ArrayToString($aCheck[$j], " ", 1, 4) to get 4 results in the message box? Link to comment Share on other sites More sharing options...
iamtheky Posted August 3, 2019 Share Posted August 3, 2019 in before the good regexes show up #include<array.au3> Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] Local $aIgnore[3] = ["b", "d", "g"] msgbox(0, '' , stringreplace(stringregexpreplace(_ArrayToString($aCheck , ",") , _ArrayToString($aIgnore) , "") , ",," , ",")) prodesigner 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
prodesigner Posted August 3, 2019 Author Share Posted August 3, 2019 (edited) Thanks this one is interesting too. Additionally, to make the result shorter, is this the right way or there is a better one? #include<array.au3> Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] Local $aIgnore[3] = ["b", "d", "g"] $work = stringreplace(stringregexpreplace(_ArrayToString($aCheck , ",") , _ArrayToString($aIgnore) , "") , ",," , ",") $work_split = StringSplit($work, ",") $work_array = _ArrayToString($work_split, ", ", 1, 4) MsgBox($MB_SYSTEMMODAL, "", $work_array) Exit Edited August 3, 2019 by prodesigner Link to comment Share on other sites More sharing options...
iamtheky Posted August 3, 2019 Share Posted August 3, 2019 the right way will depend on what the actual data is. As long as it is single characters and simple criteria you get to choose from 1000s of ways to skin it. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
prodesigner Posted August 5, 2019 Author Share Posted August 5, 2019 I am trying to get rid of the number 4 in the result, tried adding ,0 or ,1 after $sString &= $aCheck[$j] & "," no luck. #include <MsgBoxConstants.au3> ; for messages #include <File.au3> ; for split path #include <Array.au3> ; for tags Global $Title = "One time is not enough, two times..." Global $Title_Lowercase = StringLower($Title) Local $aCheck = StringSplit("one two three four", " ") Local $aIgnore = StringSplit($Title_Lowercase, " ") $sString = "" For $j = 0 To UBound($aCheck) - 1 ; Get the next item in the array to check $sItem = $aCheck[$j] ; Set a flag $fValid = True ; Now loop through the exceptions For $i = 0 To UBound($aIgnore) - 1 ; If it matches clear the flag If $sItem == $aIgnore[$i] Then $fValid = False EndIf Next ; If the flag is set it is a valid item If $fValid Then $sString &= $aCheck[$j] & "," Next MsgBox($MB_OK, "MyString", StringTrimRight($sString, 1)) Exit Link to comment Share on other sites More sharing options...
iamtheky Posted August 5, 2019 Share Posted August 5, 2019 It's the return count from your stringsplit, which you can disable with a flag. Go slow, and use _arraydisplay liberally. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
prodesigner Posted August 5, 2019 Author Share Posted August 5, 2019 Got it, thanks! 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