Jump to content

How do you read strings in a file, if they contain quotes already?


Recommended Posts

I have a good handle on how to read a file line by line, and search for a given string.

Basically using, FileOpen, FileReadLine, and StringInStr.

I have been trying to figure out why my search keeps coming back with no match.

For example, if my string line was "Where is Waldy", and I was searching for Waldy that comes back fine.

But in my file, Let's say it is

Where is "Waldy"

So i read that line in and do a search for Waldy, but i comes back with no match since there is quotes around it.

Is there a way to resolve this?

Here is my actual example

The line comes back like this

    <JposEntry logicalName="LineDisp_iSC480">

I'm searching for LineDisp_iSC480, but its coming back with no match due to the quotes.

Thanks in advance, James

Edited by MrSparty1995
adding a better example
Link to comment
Share on other sites

  • Developers

This doesn't make sense (yet).

Create a snippet that demonstrates this issue so we understand it better.

Jos

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


While 1
    ; read each line from a file
    $line_read = FileReadLine($handle_read)
    ; exit the loop if end of file
    If @error Then ExitLoop
   ; write to the ini file
   if StringInStr($line_read, "LineDisp_iSC480") = 1 Then
      MsgBox(0, "Result", "LineDisp_iSC480 was found, no need to append")

When I do a FileReadLine

It looks like this

   <JposEntry logicalName="LineDisp_iSC480">

When I do the above search, it comes back with no match

Link to comment
Share on other sites

  • Developers

It isn't that hard to make a snippet that one can actually run! ;)

Have a look at this one:

FileDelete("test.txt")
FileWriteLine("test.txt", ' <JposEntry logicalName="LineDisp_iSC480">')

$handle_read = FileOpen("test.txt")

While 1
    ; read each line from a file
    $line_read = FileReadLine($handle_read)
    ; exit the loop if end of file
    If @error Then ExitLoop
    ; write to the ini file
    If StringInStr($line_read, "LineDisp_iSC480") Then
        MsgBox(0, "Result", "LineDisp_iSC480 was found, no need to append")
    EndIf
WEnd

Jos

Edited by Jos

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

  • Moderators

@MrSparty1995 (let's hope that doesn't mean you're an MSU fan) Based on your text file, this works just fine for me

#include <Array.au3>
#include <File.au3>

Local $aArray
_FileReadToArray(<path to text file>, $aArray)
    For $i = 1 To $aArray[0]
        If StringInStr($aArray[$i], '<JposEntry logicalName="LineDisp_iSC480">') Then
            ConsoleWrite("Found what I was looking for on line: " & $i & @CRLF)
        EndIf
    Next

Also moved to proper forum

Edited by JLogan3o13

"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

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
 Share

×
×
  • Create New...