Jump to content
Sign in to follow this  

Read a File

Recommended Posts


I something like this has probably been posted a million times. I did quite a bit of searching and could not find another case that was closely enough related so that I could figure this out.

I have a text file that looks like this for example:

paper,el papel

Now I want the program to read the file using the variable $word_eng to look for the first term.

$word_eng = "hello"

then i want it to find $word_eng and take the word after the comma "hola" and make it equal to $word_esp

so pretty much $word_eng = "hello" then $word_esp = "hola"

There is more to the program this is all I need help with though.

Anyone got any ideas?

Share this post

Link to post
Share on other sites

Here Ya Go!

#include <file.au3>

; Each line of file is "English,Spanish"
Global $sFile = @ScriptDir & "\Dictionary.txt"
Global $avFile, $word_esp = "<not found>"

; Get Word to search for
$word_eng = InputBox("English", "Enter Word:")
If @error Then Exit

; Read file into an array
_FileReadToArray($sFile, $avFile)
If @error Then
    MsgBox(16, "Error", "Error opening file: " & $sFile)

; Search array for English and Spanish words
For $i = 1 To $avFile[0]
    If StringLeft($avFile[$i], StringLen($word_eng) + 1) = $word_eng & ","  Then
        $word_esp = StringStripWS(StringMid($avFile[$i], StringInStr($avFile[$i], ",") + 1), 8)

; Display results
MsgBox(64, "Results", "English:  " & $word_eng & @CRLF & "Spanish:  " & $word_esp)

*Welcome to the forums :)

Edited by Hatcheda

Share this post

Link to post
Share on other sites

#include <File.au3>

Dim $myArray

If Not _FileReadToArray("somefile.txt", $myArray) Then
   MsgBox(4096,"Error", " Error reading file to Array     error:" & @error)


Func translate($word_eng)
    For $X = 1 to $myArray[0]
        $tempArray = StringSplit($myArray[$X],",")
        If $tempArray[1] = $word_eng Then Return $tempArray[2]
    Return SetError(1,1,"")

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.