adam Posted September 25, 2020 Share Posted September 25, 2020 (edited) Looking to use stringregexp to see if: "status":"Offline" is in file status.txt. Note I need all 4 quotation marks to be present as well. $string = """status":"Offline""" FileOpen("status.txt") $status = FileRead("status.txt") If StringRegExp($status, $string) Then MsgBox(0, "", "true") EndIf It's returning true on the "status" part alone. I could have "status":"garbage" in there and will return true. I found a work around by making another text file called string.txt and putting "status":"Offline" into it. I then changed as follows and it worked. FileOpen("string.txt") $string = FileRead("string.txt") FileOpen("status.txt") $status = FileRead("status.txt") If StringRegExp($status, $string) Then MsgBox(0, "", "true") EndIf I'd appreciate help with setting $string to "status":"Offline" in the script itself. I am pretty sure I need to escape the quotation marks around "Offline"? Edited September 25, 2020 by adam Link to comment Share on other sites More sharing options...
TheXman Posted September 25, 2020 Share Posted September 25, 2020 (edited) Why don't you use: '"status":"Offline"' That's your target string wrapped in single quotes. Unless using a regular expression is a requirement, that should work in a simple StringInStr also. Look at the "Strings" section under the data types topic for an explanation: https://www.autoitscript.com/autoit3/docs/intro/lang_datatypes.htm Edited September 25, 2020 by TheXman Musashi 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Musashi Posted September 25, 2020 Share Posted September 25, 2020 @adam : Here a quick example for @TheXman 's suggestion : Local $sSearch = '"status":"Offline"' FileOpen("status.txt") Local $sRead = FileRead("status.txt") ConsoleWrite($sRead & @CRLF) If StringRegExp($sRead, '(?i)' & '\Q' & $sSearch & '\E') Then ConsoleWrite("+ Found : " & $sSearch & @CRLF) Else ConsoleWrite("! Not Found : " & $sSearch & @CRLF) EndIf "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
adam Posted September 25, 2020 Author Share Posted September 25, 2020 (edited) Thank you for the help. I had initially tried ""status":"Offline"" but autoit wasn't happy with it. I'll do some reading in that section because to me '"status":"Offline"' should be no different than ""status":"Offline"" Edited September 25, 2020 by adam Link to comment Share on other sites More sharing options...
TheXman Posted September 25, 2020 Share Posted September 25, 2020 (edited) 8 minutes ago, adam said: I need to do some reading because shouldn't '"status":"Offline"' be no different than ""status":"Offline""? That would actually be: """status"":""Offline""" If you were going to use double quotes to enclose the string, then every double quote within the string would need to be escaped (""). $string = """status"":""Offline""" ConsoleWrite($string & @CRLF) Console: "status":"Offline" Edited September 25, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
adam Posted September 25, 2020 Author Share Posted September 25, 2020 Very helpful appreciate it Link to comment Share on other sites More sharing options...
TheXman Posted September 25, 2020 Share Posted September 25, 2020 You're welcome! CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Musashi Posted September 25, 2020 Share Posted September 25, 2020 You can probably even omit " at the beginning and end of the string, and just search for status":"Offline Local $sSearch = 'status":"Offline' or : Local $sSearch = 'status' & Chr(34) & ':' & Chr(34) & 'Offline' TheXman 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." 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